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 page keywords.
-
#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 back.
Instance Method Details
#description(description) ⇒ String
Set the page description.
93 94 95 96 |
# File 'lib/meta_tags/view_helper.rb', line 93 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 layout file.
180 181 182 |
# File 'lib/meta_tags/view_helper.rb', line 180 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 display_meta_tags helper) will not be rendered, so you have to pass default arguments like site title in here. You probably want to define helper with default options to minimize code duplication.
205 206 207 |
# File 'lib/meta_tags/view_helper.rb', line 205 def display_title(defaults = {}) .full_title(defaults) end |
#keywords(keywords) ⇒ String, Array
Set the page keywords.
75 76 77 78 |
# File 'lib/meta_tags/view_helper.rb', line 75 def keywords(keywords) (keywords: keywords) keywords end |
#meta_tags ⇒ Object
Get meta tags for the page.
8 9 10 |
# File 'lib/meta_tags/view_helper.rb', line 8 def @meta_tags ||= MetaTagsCollection.new end |
#nofollow(nofollow = true) ⇒ Boolean, ...
Set the nofollow meta tag
125 126 127 128 |
# File 'lib/meta_tags/view_helper.rb', line 125 def nofollow(nofollow = true) (nofollow: nofollow) nofollow end |
#noindex(noindex = true) ⇒ Boolean, ...
Set the noindex meta tag
109 110 111 112 |
# File 'lib/meta_tags/view_helper.rb', line 109 def noindex(noindex = true) (noindex: noindex) noindex end |
#refresh(refresh) ⇒ Integer, String
Set the refresh meta tag
141 142 143 144 |
# File 'lib/meta_tags/view_helper.rb', line 141 def refresh(refresh) (refresh: refresh) refresh end |
#set_meta_tags(meta_tags = {}) ⇒ Object
Set meta tags for the page.
Method could be used several times, and all options passed will be merged. If you will set the same property several times, last one will take precedence.
Usually you will not call this method directly. Use #title, #keywords, #description for your daily tasks.
30 31 32 |
# File 'lib/meta_tags/view_helper.rb', line 30 def ( = {}) self..update() end |
#title(title = nil, headline = "") ⇒ String
Set the page title and return it back.
This method is best suited for use in helpers. It sets the page title and returns it (or headline
if specified).
58 59 60 61 |
# File 'lib/meta_tags/view_helper.rb', line 58 def title(title = nil, headline = "") (title: title) unless title.nil? headline.presence || [:title] end |