Module: Decidim::MetaTagsHelper
- Included in:
- Admin::ApplicationHelper
- Defined in:
- decidim-core/app/helpers/decidim/meta_tags_helper.rb
Overview
Helper that provides convenient methods to deal with the page meta tags.
Instance Attribute Summary collapse
-
#decidim_meta_description ⇒ Object
readonly
Returns the value of attribute decidim_meta_description.
-
#decidim_meta_image_url ⇒ Object
readonly
Returns the value of attribute decidim_meta_image_url.
-
#decidim_meta_twitter_handler ⇒ Object
readonly
Returns the value of attribute decidim_meta_twitter_handler.
-
#decidim_meta_url ⇒ Object
readonly
Returns the value of attribute decidim_meta_url.
Instance Method Summary collapse
-
#add_decidim_meta_description(description) ⇒ Object
Sets the meta description for the current page.
-
#add_decidim_meta_image_url(image_url) ⇒ Object
Sets the meta image URL for the current page.
-
#add_decidim_meta_tags(tags) ⇒ Object
Public: Sets the given metatags for the page.
-
#add_decidim_meta_twitter_handler(twitter_handler) ⇒ Object
Sets the meta Twitter handler for the current page.
-
#add_decidim_meta_url(url) ⇒ Object
Sets the meta URL for the current page.
-
#add_decidim_page_title(title) ⇒ Object
Public: Accumulates the given ‘title` so that they can be chained.
-
#decidim_page_title ⇒ Object
Public: Renders the title for a page.
Instance Attribute Details
#decidim_meta_description ⇒ Object (readonly)
Returns the value of attribute decidim_meta_description.
50 51 52 |
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 50 def end |
#decidim_meta_image_url ⇒ Object (readonly)
Returns the value of attribute decidim_meta_image_url.
50 51 52 |
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 50 def end |
#decidim_meta_twitter_handler ⇒ Object (readonly)
Returns the value of attribute decidim_meta_twitter_handler.
50 51 52 |
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 50 def end |
#decidim_meta_url ⇒ Object (readonly)
Returns the value of attribute decidim_meta_url.
50 51 52 |
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 50 def end |
Instance Method Details
#add_decidim_meta_description(description) ⇒ Object
Sets the meta description for the current page. We want to keep the most specific one, so you cannot replace the description if it is set by a view that has already been rendered. Remember that Rails’s views are render inside-out, so the ‘layout` is the last one to be rendered. You can put there a basic content and override it in other layers.
description - The String to be set as description
Returns nothing.
62 63 64 |
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 62 def (description) ||= (description) end |
#add_decidim_meta_image_url(image_url) ⇒ Object
Sets the meta image URL for the current page. We want to keep the most specific one, so you cannot replace the image URL if it is set by a view that has already been rendered. Remember that Rails’s views are render inside-out, so the ‘layout` is the last one to be rendered. You can put there a basic content and override it in other layers.
image_url - The String to be set as image URL
Returns nothing.
101 102 103 |
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 101 def (image_url) ||= image_url end |
#add_decidim_meta_tags(tags) ⇒ Object
Public: Sets the given metatags for the page. It’s a wrapper for the individual methods, so that you can set multiple values with a single call. See the docs for the other methods to see how they work.
tags - A Hash containing the meta tag name as keys and its content as values.
Returns nothing.
13 14 15 16 17 18 19 |
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 13 def () add_decidim_page_title([:title]) ([:description]) ([:url]) ([:twitter_handler]) ([:image_url]) end |
#add_decidim_meta_twitter_handler(twitter_handler) ⇒ Object
Sets the meta Twitter handler for the current page. We want to keep the most specific one, so you cannot replace the Twitter handler if it is set by a view that has already been rendered. Remember that Rails’s views are render inside-out, so the ‘layout` is the last one to be rendered. You can put there a basic content and override it in other layers.
twitter_handler - The String to be set as Twitter handler
Returns nothing.
75 76 77 |
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 75 def (twitter_handler) ||= twitter_handler end |
#add_decidim_meta_url(url) ⇒ Object
Sets the meta URL for the current page. We want to keep the most specific one, so you cannot replace the URL if it is set by a view that has already been rendered. Remember that Rails’s views are render inside-out, so the ‘layout` is the last one to be rendered. You can put there a basic content and override it in other layers.
url - The String to be set as URL
Returns nothing.
88 89 90 |
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 88 def (url) ||= url end |
#add_decidim_page_title(title) ⇒ Object
Public: Accumulates the given ‘title` so that they can be chained. Since Rails views are rendered inside-out, `title` is appended to an array. This way the beggining of the title will be the most specific one. Use the `decidim_page_title` method to render the title whenever you need to (most surely, in the `<title>` tag in the HTML head and in some `title` metatags).
Example:
add_decidim_page_title("My Process")
add_decidim_page_title("My Organization")
decidim_page_title # => "My Process - My Organization"
title - A String to be added to the title
Returns an Array of Strings.
35 36 37 38 39 |
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 35 def add_decidim_page_title(title) @decidim_page_title ||= [] return @decidim_page_title unless title.present? @decidim_page_title << title end |
#decidim_page_title ⇒ Object
Public: Renders the title for a page. Use the ‘add_decidim_page_title` method to accumulate elements for the title. Basically, it joins the elements of the title array with `“ - ”`.
Returns a String.
46 47 48 |
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 46 def decidim_page_title (@decidim_page_title || []).join(" - ") end |