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

Instance Method Summary collapse

Instance Attribute Details

#decidim_meta_descriptionObject (readonly)

Returns the value of attribute decidim_meta_description


52
53
54
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 52

def decidim_meta_description
  @decidim_meta_description
end

#decidim_meta_image_urlObject (readonly)

Returns the value of attribute decidim_meta_image_url


52
53
54
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 52

def decidim_meta_image_url
  @decidim_meta_image_url
end

#decidim_meta_twitter_handlerObject (readonly)

Returns the value of attribute decidim_meta_twitter_handler


52
53
54
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 52

def decidim_meta_twitter_handler
  @decidim_meta_twitter_handler
end

#decidim_meta_urlObject (readonly)

Returns the value of attribute decidim_meta_url


52
53
54
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 52

def decidim_meta_url
  @decidim_meta_url
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.


64
65
66
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 64

def add_decidim_meta_description(description)
  @decidim_meta_description ||= strip_tags(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.


103
104
105
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 103

def add_decidim_meta_image_url(image_url)
  @decidim_meta_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.


14
15
16
17
18
19
20
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 14

def add_decidim_meta_tags(tags)
  add_decidim_page_title(tags[:title])
  add_decidim_meta_description(tags[:description])
  add_decidim_meta_url(tags[:url])
  add_decidim_meta_twitter_handler(tags[:twitter_handler])
  add_decidim_meta_image_url(tags[: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.


77
78
79
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 77

def add_decidim_meta_twitter_handler(twitter_handler)
  @decidim_meta_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.


90
91
92
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 90

def add_decidim_meta_url(url)
  @decidim_meta_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.


36
37
38
39
40
41
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 36

def add_decidim_page_title(title)
  @decidim_page_title ||= []
  return @decidim_page_title if title.blank?

  @decidim_page_title << title
end

#decidim_page_titleObject

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.


48
49
50
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 48

def decidim_page_title
  (@decidim_page_title || []).join(" - ")
end