Module: M3ta::Helpers

Defined in:
lib/m3ta/helpers.rb

Instance Method Summary collapse

Instance Method Details

#description_tagsObject



83
84
85
86
87
88
89
90
91
# File 'lib/m3ta/helpers.rb', line 83

def description_tags
  return unless m3ta.description
  
  [
    m3ta_tag(name: 'description', content: m3ta.description),
    m3ta_tag(property: 'og:description', content: m3ta.description),
    m3ta_tag(name: 'twitter:description', content: m3ta.description)
  ]
end

#facebook_tagsObject



31
32
33
34
35
# File 'lib/m3ta/helpers.rb', line 31

def facebook_tags
  [
    m3ta.facebook_app_id.presence && m3ta_tag(property: 'fb:app_id', content: m3ta.facebook_app_id) 
  ]
end

#image_tagsObject



62
63
64
65
66
67
68
69
# File 'lib/m3ta/helpers.rb', line 62

def image_tags
  return unless m3ta.image

  [
    m3ta_tag(property: 'og:image', content: m3ta.image),
    m3ta_tag(name: 'twitter:image:src', content: m3ta.image)
  ]
end

#keywordsObject



93
94
95
96
97
# File 'lib/m3ta/helpers.rb', line 93

def keywords
  @keywords ||= Array[m3ta.keywords].flatten.select(&:present?).map do |section|
    section.to_s.split(',')
  end.flatten.select(&:present?).map(&:strip).uniq.join(', ')
end

#keywords_tagsObject



56
57
58
59
60
# File 'lib/m3ta/helpers.rb', line 56

def keywords_tags
  return unless keywords.present?

  m3ta_tag(name: 'keywords', content: keywords)
end

#m3ta_tag(options = {}) ⇒ Object



107
108
109
# File 'lib/m3ta/helpers.rb', line 107

def m3ta_tag(options = {})
  tag(:meta, options)
end

#m3ta_tagsObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/m3ta/helpers.rb', line 5

def m3ta_tags
  [
    facebook_tags,
    twitter_tags,
    m3ta_tag(property: 'og:type', content: m3ta.type || 'website'),
    m3ta_tag(property: 'og:site_name', content: site_name),
    m3ta_tag(property: 'og:url', content: url),
    tag(:link, rel: 'canonical', href: url),
    title_tags,
    description_tags,
    player_tags,
    image_tags,
    video_tags,
    keywords_tags
  ].flatten.compact.join("\n").html_safe
end

#player_tagsObject



46
47
48
49
50
51
52
53
54
# File 'lib/m3ta/helpers.rb', line 46

def player_tags
  return unless m3ta.player.present?

  [
    m3ta_tag(name: 'twitter:player', content: m3ta.player),
    m3ta_tag(name: 'twitter:player:width', content: '1280'),
    m3ta_tag(name: 'twitter:player:height', content: '720')
  ]
end

#site_nameObject



99
100
101
# File 'lib/m3ta/helpers.rb', line 99

def site_name
  m3ta.site_name
end

#title_tagsObject



22
23
24
25
26
27
28
29
# File 'lib/m3ta/helpers.rb', line 22

def title_tags
  [
    (:title, m3ta.title),
    m3ta_tag(name: 'title', content: m3ta.title),
    m3ta_tag(property: 'og:title', content: m3ta.title),
    m3ta_tag(name: 'twitter:title', content: m3ta.title)
  ]
end

#twitter_tagsObject



37
38
39
40
41
42
43
44
# File 'lib/m3ta/helpers.rb', line 37

def twitter_tags
  card = m3ta.player.present? ? 'player' : 'summary_large_image'
  [
    m3ta.twitter_handle.presence && m3ta_tag(name: 'twitter:site', content: m3ta.twitter_handle),
    m3ta.twitter_handle.presence && m3ta_tag(name: 'twitter:creator', content: m3ta.twitter_handle),
    m3ta_tag(name: 'twitter:card', content: card)
  ]
end

#urlObject



103
104
105
# File 'lib/m3ta/helpers.rb', line 103

def url
  (m3ta.url || request.url).split('?')[0]
end

#video_tagsObject



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/m3ta/helpers.rb', line 71

def video_tags
  return unless m3ta.video

  [
    m3ta_tag(property: 'og:video:url', content: m3ta.video),
    m3ta_tag(property: 'og:video:secure_url', content: m3ta.video),
    m3ta_tag(property: 'og:video:width', content: m3ta.video_width),
    m3ta_tag(property: 'og:video:height', content: m3ta.video_height),
    m3ta_tag(property: 'og:video:type', content: m3ta.video_type)
  ]
end