Module: JT::Rails::Meta
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActionView::Helpers::TagHelper
- Defined in:
- lib/jt-rails-meta.rb
Instance Method Summary collapse
-
#add_meta_extra(extra_params, previous_key = nil) ⇒ Object
- Add meta other than title, description, keywords Params:
extra_params -
hash containing the meta(s) wanted.
- Add meta other than title, description, keywords Params:
-
#add_meta_keywords(keywords) ⇒ Object
- Add custom keywords to the meta keywords, must be call before ‘set_meta_keywords` Params:
keywords -
array of keywords added to the default keywords.
- Add custom keywords to the meta keywords, must be call before ‘set_meta_keywords` Params:
-
#add_meta_link(rel, href, options = {}) ⇒ Object
Add links to meta, used for add ‘canonicalæ or ’publisher’ links.
- #add_meta_link_alternate(url, lang) ⇒ Object
- #add_meta_link_author(url) ⇒ Object
-
#add_meta_link_canonical(url) ⇒ Object
Helpers.
- #add_meta_link_publisher(url) ⇒ Object
-
#meta_description ⇒ Object
Content of meta description.
-
#meta_keywords ⇒ Object
Content of meta keywords.
-
#meta_tags ⇒ Object
Generate HTML tags title, description, keywords and others meta.
-
#meta_title ⇒ Object
Content of meta title.
-
#meta_title_raw ⇒ Object
Content of meta title without suffix or prefix.
-
#set_meta_description(options = {}) ⇒ Object
- Generate meta description Use meta.default.description if no meta found for the current controller/action Params:
options -
options passed to I18n.
- Generate meta description Use meta.default.description if no meta found for the current controller/action Params:
-
#set_meta_keywords(options = {}) ⇒ Object
- Generate meta keywords Use meta.default.keywords if no meta found for the current controller/action Params:
options -
options passed to I18n.
- Generate meta keywords Use meta.default.keywords if no meta found for the current controller/action Params:
-
#set_meta_title(options = {}) ⇒ Object
- Generate meta title Use meta.default.title if no meta found for the current controller/action Params:
options -
options passed to I18n.
- Generate meta title Use meta.default.title if no meta found for the current controller/action Params:
Instance Method Details
#add_meta_extra(extra_params, previous_key = nil) ⇒ Object
Add meta other than title, description, keywords Params:
extra_params-
hash containing the meta(s) wanted
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/jt-rails-meta.rb', line 124 def (extra_params, previous_key = nil) for key, value in extra_params current_key = previous_key ? "#{previous_key}:#{key}" : key if value.is_a?(String) || value.is_a?(Symbol) [:extra] << { name: current_key, content: value.to_s } elsif value.is_a?(Hash) (value, current_key) elsif value.is_a?(Array) for v in value [:extra] << { name: current_key, content: v.to_s } end end end end |
#add_meta_keywords(keywords) ⇒ Object
Add custom keywords to the meta keywords, must be call before ‘set_meta_keywords` Params:
keywords-
array of keywords added to the default keywords
111 112 113 114 115 116 117 118 119 |
# File 'lib/jt-rails-meta.rb', line 111 def (keywords) if keywords.is_a?(String) [:keywords] = keywords elsif keywords.is_a?(Array) [:keywords] = keywords.join(',') end end |
#add_meta_link(rel, href, options = {}) ⇒ Object
Add links to meta, used for add ‘canonicalæ or ’publisher’ links
141 142 143 144 |
# File 'lib/jt-rails-meta.rb', line 141 def (rel, href, = {}) .merge!(rel: rel, href: href) [:links] << {options: } end |
#add_meta_link_alternate(url, lang) ⇒ Object
160 161 162 |
# File 'lib/jt-rails-meta.rb', line 160 def (url, lang) 'alternate', url, hreflang: lang end |
#add_meta_link_author(url) ⇒ Object
152 153 154 |
# File 'lib/jt-rails-meta.rb', line 152 def (url) 'author', url end |
#add_meta_link_canonical(url) ⇒ Object
Helpers
148 149 150 |
# File 'lib/jt-rails-meta.rb', line 148 def (url) 'canonical', url end |
#add_meta_link_publisher(url) ⇒ Object
156 157 158 |
# File 'lib/jt-rails-meta.rb', line 156 def (url) 'publisher', url end |
#meta_description ⇒ Object
Content of meta description
47 48 49 |
# File 'lib/jt-rails-meta.rb', line 47 def [:description] ||= end |
#meta_keywords ⇒ Object
Content of meta keywords
52 53 54 |
# File 'lib/jt-rails-meta.rb', line 52 def [:keywords] ||= end |
#meta_tags ⇒ Object
Generate HTML tags title, description, keywords and others meta
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/jt-rails-meta.rb', line 18 def output = '' output << content_tag('title', ) output << "\n" output << tag('meta', name: 'description', content: ) output << "\n" output << tag('meta', name: 'keywords', content: ) output << "\n" for link in [:links] output << tag('link', link[:options]) output << "\n" end for extra_params in [:extra] output << tag('meta', name: extra_params[:name], content: extra_params[:content]) output << "\n" end output.html_safe end |
#meta_title ⇒ Object
Content of meta title
42 43 44 |
# File 'lib/jt-rails-meta.rb', line 42 def [:title] ||= end |
#meta_title_raw ⇒ Object
Content of meta title without suffix or prefix
57 58 59 |
# File 'lib/jt-rails-meta.rb', line 57 def [:title_raw] end |
#set_meta_description(options = {}) ⇒ Object
Generate meta description Use meta.default.description if no meta found for the current controller/action Params:
options-
options passed to I18n
84 85 86 87 88 |
# File 'lib/jt-rails-meta.rb', line 84 def ( = {}) [:description] = I18n.translate("#{meta_key}.description", ) [:description] = I18n.translate('meta.default.description') if !have_translation?([:description]) [:description] end |
#set_meta_keywords(options = {}) ⇒ Object
Generate meta keywords Use meta.default.keywords if no meta found for the current controller/action Params:
options-
options passed to I18n
94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/jt-rails-meta.rb', line 94 def ( = {}) keywords = I18n.translate("#{meta_key}.keywords", ) keywords = I18n.translate('meta.default.keywords') if !have_translation?(keywords) keywords = '' if !have_translation?(keywords) if [:keywords].blank? [:keywords] = keywords else [:keywords] << ',' << keywords end [:keywords] end |
#set_meta_title(options = {}) ⇒ Object
Generate meta title Use meta.default.title if no meta found for the current controller/action Params:
options-
options passed to I18n
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/jt-rails-meta.rb', line 65 def ( = {}) [:title_raw] = I18n.translate("#{meta_key}.title", ) if have_translation?([:title_raw]) [:title] = "#{@meta[:prefix]}#{@meta[:title_raw]}#{@meta[:suffix]}" else [:title] = I18n.translate("#{meta_key}.full_title", ) [:title] = I18n.translate('meta.default.title') if !have_translation?([:title]) [:title_raw] = [:title] end [:title] end |