Module: MetaTags::ViewHelper
- Defined in:
- lib/meta_tags/view_helper.rb
Overview
Contains methods to use in views and helpers.
Instance Method Summary collapse
-
#description(description) ⇒ String
Set the page description.
-
#display_meta_tags(defaults = {}) ⇒ String
Set default meta tag values and display meta tags.
-
#display_title(defaults = {}) ⇒ Object
Returns full page title as a string without surrounding <title> tag.
-
#keywords(keywords) ⇒ String, Array
Set the legacy keywords meta tag.
-
#meta_tags ⇒ Object
Get meta tags for the page.
-
#nofollow(nofollow = true) ⇒ Boolean, ...
Set the nofollow meta tag.
-
#noindex(noindex = true) ⇒ Boolean, ...
Set the noindex meta tag.
-
#refresh(refresh) ⇒ Integer, String
Set the refresh meta tag.
-
#set_meta_tags(meta_tags = {}) ⇒ Object
Set meta tags for the page.
-
#title(title = nil, headline = "") ⇒ String
Set the page title and return it.
Instance Method Details
#description(description) ⇒ String
Set the page description.
84 85 86 87 |
# File 'lib/meta_tags/view_helper.rb', line 84 def description(description) (description: description) description end |
#display_meta_tags(defaults = {}) ⇒ String
Set default meta tag values and display meta tags. This method should be used in the layout file.
164 165 166 |
# File 'lib/meta_tags/view_helper.rb', line 164 def (defaults = {}) .with_defaults(defaults) { Renderer.new().render(self) } end |
#display_title(defaults = {}) ⇒ Object
Returns full page title as a string without surrounding <title> tag.
The only case when you may need this helper is when you use PJAX. This means that your layout file (with the display_meta_tags helper) will not be rendered, so you have to pass default arguments such as the site title here. You probably want to define a helper with default options to minimize code duplication.
192 193 194 |
# File 'lib/meta_tags/view_helper.rb', line 192 def display_title(defaults = {}) .full_title(defaults) end |
#keywords(keywords) ⇒ String, Array
Set the legacy keywords meta tag.
Modern search engines ignore this tag, but some older integrations and internal systems may still read it.
69 70 71 72 |
# File 'lib/meta_tags/view_helper.rb', line 69 def keywords(keywords) (keywords: keywords) keywords end |
#meta_tags ⇒ Object
Get meta tags for the page.
7 8 9 |
# File 'lib/meta_tags/view_helper.rb', line 7 def @meta_tags ||= MetaTagsCollection.new end |
#nofollow(nofollow = true) ⇒ Boolean, ...
Set the nofollow meta tag.
110 111 112 113 |
# File 'lib/meta_tags/view_helper.rb', line 110 def nofollow(nofollow = true) (nofollow: nofollow) nofollow end |
#noindex(noindex = true) ⇒ Boolean, ...
Set the noindex meta tag.
97 98 99 100 |
# File 'lib/meta_tags/view_helper.rb', line 97 def noindex(noindex = true) (noindex: noindex) noindex end |
#refresh(refresh) ⇒ Integer, String
Set the refresh meta tag.
123 124 125 126 |
# File 'lib/meta_tags/view_helper.rb', line 123 def refresh(refresh) (refresh: refresh) refresh end |
#set_meta_tags(meta_tags = {}) ⇒ Object
Set meta tags for the page.
This method can be used several times, and all passed options will be merged. If you set the same property several times, the last one will take precedence.
Usually you will not call this method directly. Use helpers like #title, #description, #noindex, and #canonical for daily tasks. #keywords remains available for legacy compatibility.
27 28 29 |
# File 'lib/meta_tags/view_helper.rb', line 27 def ( = {}) self..update() end |
#title(title = nil, headline = "") ⇒ String
Set the page title and return it.
This method is best suited for use in helpers. It sets the page title and returns it (or headline if specified).
52 53 54 55 |
# File 'lib/meta_tags/view_helper.rb', line 52 def title(title = nil, headline = "") (title: title) unless title.nil? headline.presence || .page_title end |