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.



50
51
52
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 50

def decidim_meta_description
  @decidim_meta_description
end

#decidim_meta_image_urlObject (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 decidim_meta_image_url
  @decidim_meta_image_url
end

#decidim_meta_twitter_handlerObject (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 decidim_meta_twitter_handler
  @decidim_meta_twitter_handler
end

#decidim_meta_urlObject (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 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.



62
63
64
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 62

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.



101
102
103
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 101

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.



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

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.



75
76
77
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 75

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.



88
89
90
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 88

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.



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_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.



46
47
48
# File 'decidim-core/app/helpers/decidim/meta_tags_helper.rb', line 46

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