Module: MetaHelper
- Defined in:
- app/helpers/meta_helper.rb
Overview
View helper: meta.
Instance Method Summary collapse
- #build_title(*args) ⇒ Object
-
#downgrade_h1_tags(html) ⇒ Object
Converts any tags in rich-text HTML to to prevent multiple H1s when the template already defines one.
-
#effective_page_tag ⇒ Object
Returns the effective page tag: override if set, otherwise @main_tag from controller.
- #og_image_asset_url(image_id, options = {}) ⇒ Object
- #page_author(author) ⇒ Object
- #page_description(description) ⇒ Object
- #page_keywords(keywords) ⇒ Object
- #page_og_image(image_id_or_image) ⇒ Object
- #page_robot_directive(directive) ⇒ Object
-
#page_tag(page_path) ⇒ Object
Overrides the automatic page tag (set by PagesController) with a custom value.
- #page_title(*args) ⇒ Object
- #set_metas(title: DEFAULT_PAGE_TITLE, description: DEFAULT_PAGE_TITLE, keywords: DEFAULT_PAGE_KEYWORDS) ⇒ Object
- #swiftype_robot_exclude ⇒ Object
- #swiftype_type(type) ⇒ Object
Instance Method Details
#build_title(*args) ⇒ Object
81 82 83 84 |
# File 'app/helpers/meta_helper.rb', line 81 def build_title(*args) links = args.compact.uniq page_title links.join(' > ') end |
#downgrade_h1_tags(html) ⇒ Object
Converts any tags in rich-text HTML to to prevent
multiple H1s when the template already defines one.
88 89 90 91 92 |
# File 'app/helpers/meta_helper.rb', line 88 def (html) return html if html.blank? html.gsub(%r{<(/?)h1(\s|>)}i) { "<#{::Regexp.last_match(1)}h2#{::Regexp.last_match(2)}" } end |
#effective_page_tag ⇒ Object
Returns the effective page tag: override if set, otherwise @main_tag from controller
63 64 65 |
# File 'app/helpers/meta_helper.rb', line 63 def effective_page_tag @page_tag_override || @main_tag end |
#og_image_asset_url(image_id, options = {}) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/helpers/meta_helper.rb', line 94 def og_image_asset_url(image_id, = {}) = { format: :jpeg, background: 'ffffff', width: SOCIAL_IMAGE_WIDTH, height: SOCIAL_IMAGE_HEIGHT, crop_mode: 'cm-extract', thumbnail: true }.merge() image_asset_url(image_id, **) end |
#page_author(author) ⇒ Object
14 15 16 |
# File 'app/helpers/meta_helper.rb', line 14 def () content_for(:author) { } end |
#page_description(description) ⇒ Object
8 9 10 11 12 |
# File 'app/helpers/meta_helper.rb', line 8 def page_description(description) return if description.blank? content_for(:description) { description.truncate(375, separator: /[\s|]/, omission: '') } end |
#page_keywords(keywords) ⇒ Object
4 5 6 |
# File 'app/helpers/meta_helper.rb', line 4 def page_keywords(keywords) content_for(:keywords) { keywords } end |
#page_og_image(image_id_or_image) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'app/helpers/meta_helper.rb', line 39 def page_og_image(image_id_or_image) return if @og_image_set return if image_id_or_image.blank? image_asset_url = og_image_asset_url(image_id_or_image) || DEFAULT_SOCIAL_ICON content_for(:og_image) { image_asset_url } @og_image_set = true nil end |
#page_robot_directive(directive) ⇒ Object
67 68 69 70 71 |
# File 'app/helpers/meta_helper.rb', line 67 def page_robot_directive(directive) return if directive.blank? content_for(:robots_directive) { directive } end |
#page_tag(page_path) ⇒ Object
Overrides the automatic page tag (set by PagesController) with a custom value.
Only needed when the page tag should differ from the URL-based default.
Usage: page_tag('custom/path') outputs: for-custom-path-page
53 54 55 56 57 58 59 60 |
# File 'app/helpers/meta_helper.rb', line 53 def page_tag(page_path) return if @page_tag_override_set return if page_path.blank? @page_tag_override = DigitalAsset.page_tag_for(page_path) @page_tag_override_set = true nil end |
#page_title(*args) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'app/helpers/meta_helper.rb', line 28 def page_title(*args) page_title = [args].flatten.map(&:to_s).filter_map(&:presence).uniq.join(' | ') return if page_title.blank? # Check the length of our page_title, if not too long and no WarmlyYours present in the name, add the company locale add_title_info = " | #{company_locale}" page_title << add_title_info if (page_title.size + add_title_info.size) <= 60 && !page_title.match?(/WarmlyYours/i) @page_title = page_title content_for(:title) { page_title } end |
#set_metas(title: DEFAULT_PAGE_TITLE, description: DEFAULT_PAGE_TITLE, keywords: DEFAULT_PAGE_KEYWORDS) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'app/helpers/meta_helper.rb', line 18 def ( title: DEFAULT_PAGE_TITLE, description: DEFAULT_PAGE_TITLE, keywords: DEFAULT_PAGE_KEYWORDS ) page_title title page_description description page_keywords keywords end |
#swiftype_robot_exclude ⇒ Object
77 78 79 |
# File 'app/helpers/meta_helper.rb', line 77 def swiftype_robot_exclude content_for(:swiftype_robot) { 'noindex, nofollow' } end |
#swiftype_type(type) ⇒ Object
73 74 75 |
# File 'app/helpers/meta_helper.rb', line 73 def swiftype_type(type) content_for(:swiftype_type) { type } end |