Module: MetaDataHelper

Includes:
ActionView::Helpers::AssetUrlHelper, ActionView::Helpers::TagHelper
Included in:
PostPresenter
Defined in:
app/helpers/meta_data_helper.rb

Instance Method Summary collapse

Instance Method Details

#default_author_nameObject


19
20
21
# File 'app/helpers/meta_data_helper.rb', line 19

def default_author_name
  AppConfig.settings.pod_name
end

#default_descriptionObject


23
24
25
# File 'app/helpers/meta_data_helper.rb', line 23

def default_description
  AppConfig.settings.default_metas.description
end

#default_image_urlObject


15
16
17
# File 'app/helpers/meta_data_helper.rb', line 15

def default_image_url
  asset_url("assets/branding/logos/asterisk.png", skip_pipeline: true)
end

#default_titleObject


27
28
29
# File 'app/helpers/meta_data_helper.rb', line 27

def default_title
  AppConfig.settings.default_metas.title
end

#general_metasObject


31
32
33
34
35
36
37
38
39
40
# File 'app/helpers/meta_data_helper.rb', line 31

def general_metas
  {
    description:    {name:     "description",  content: default_description},
    og_description: {property: "description",  content: default_description},
    og_site_name:   {property: "og:site_name", content: default_title},
    og_url:         {property: "og:url",       content: site_url},
    og_image:       {property: "og:image",     content: default_image_url},
    og_type:        {property: "og:type",      content: "website"}
  }
end

#meta_tag(attributes) ⇒ Object

recursively calls itself if attribute is an array (metas such as og:image or og:tag can be present multiple times with different values)


49
50
51
52
53
54
# File 'app/helpers/meta_data_helper.rb', line 49

def meta_tag(attributes)
  return "" if attributes.empty?
  return tag(:meta, attributes) unless attributes[:content].respond_to?(:to_ary)
  items = attributes.delete(:content)
  items.map {|item| meta_tag(attributes.merge(content: item)) }.join("\n")
end

#metas_tags(attributes_list = {}, with_general_metas = true) ⇒ Object


42
43
44
45
# File 'app/helpers/meta_data_helper.rb', line 42

def metas_tags(attributes_list={}, with_general_metas=true)
  attributes_list = general_metas.merge(attributes_list) if with_general_metas
  attributes_list.map {|_, attributes| meta_tag attributes }.join("\n").html_safe
end

#og_prefixObject


7
8
9
# File 'app/helpers/meta_data_helper.rb', line 7

def og_prefix
  "og: https://ogp.me/ns# article: https://ogp.me/ns/article# profile: https://ogp.me/ns/profile#"
end

#site_urlObject


11
12
13
# File 'app/helpers/meta_data_helper.rb', line 11

def site_url
  AppConfig.environment.url
end