Module: M3ta::Helpers
- Defined in:
- lib/m3ta/helpers.rb
Instance Method Summary collapse
- #description_tags ⇒ Object
- #facebook_tags ⇒ Object
- #image_tags ⇒ Object
- #keywords ⇒ Object
- #keywords_tags ⇒ Object
- #m3ta_tag(options = {}) ⇒ Object
- #m3ta_tags ⇒ Object
- #player_tags ⇒ Object
- #site_name ⇒ Object
- #title_tags ⇒ Object
- #twitter_tags ⇒ Object
- #url ⇒ Object
- #video_tags ⇒ Object
Instance Method Details
#description_tags ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/m3ta/helpers.rb', line 83 def 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_tags ⇒ Object
31 32 33 34 35 |
# File 'lib/m3ta/helpers.rb', line 31 def [ m3ta.facebook_app_id.presence && m3ta_tag(property: 'fb:app_id', content: m3ta.facebook_app_id) ] end |
#image_tags ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/m3ta/helpers.rb', line 62 def return unless m3ta.image [ m3ta_tag(property: 'og:image', content: m3ta.image), m3ta_tag(name: 'twitter:image:src', content: m3ta.image) ] end |
#keywords ⇒ Object
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_tags ⇒ Object
56 57 58 59 60 |
# File 'lib/m3ta/helpers.rb', line 56 def 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( = {}) tag(:meta, ) end |
#m3ta_tags ⇒ Object
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_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), , , , , , ].flatten.compact.join("\n").html_safe end |
#player_tags ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/m3ta/helpers.rb', line 46 def 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_name ⇒ Object
99 100 101 |
# File 'lib/m3ta/helpers.rb', line 99 def site_name m3ta.site_name end |
#title_tags ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/m3ta/helpers.rb', line 22 def [ content_tag(: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_tags ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/m3ta/helpers.rb', line 37 def 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 |
#url ⇒ Object
103 104 105 |
# File 'lib/m3ta/helpers.rb', line 103 def url (m3ta.url || request.url).split('?')[0] end |
#video_tags ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/m3ta/helpers.rb', line 71 def 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 |