Method: MetaTags::ViewHelper#display_meta_tags
- Defined in:
- lib/meta_tags/view_helper.rb
#display_meta_tags(default = {}) ⇒ String
Set default meta tag values and display meta tags. This method should be used in layout file.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/meta_tags/view_helper.rb', line 146 def (default = {}) = (default || {}).merge(@meta_tags || {}) # Prefix (leading space) prefix = [:prefix] === false ? '' : ([:prefix] || ' ') # Separator separator = [:separator].blank? ? '|' : [:separator] # Suffix (trailing space) suffix = [:suffix] === false ? '' : ([:suffix] || ' ') # Title title = [:title] if [:lowercase] === true and !title.blank? title = if title.is_a?(Array) title.map { |t| t.downcase } else title.downcase end end result = [] # title if title.blank? result << content_tag(:title, [:site]) else title = normalize_title(title) title = [[:site]] + title title.reverse! if [:reverse] === true sep = prefix + separator + suffix result << content_tag(:title, title.join(sep)) end # description description = normalize_description([:description]) result << tag(:meta, :name => :description, :content => description) unless description.blank? # keywords keywords = normalize_keywords([:keywords]) result << tag(:meta, :name => :keywords, :content => keywords) unless keywords.blank? # noindex & nofollow noindex_name = [:noindex].is_a?(String) ? [:noindex] : 'robots' nofollow_name = [:nofollow].is_a?(String) ? [:nofollow] : 'robots' if noindex_name == nofollow_name content = [([:noindex] ? 'noindex' : nil), ([:nofollow] ? 'nofollow' : nil)].compact.join(', ') result << tag(:meta, :name => noindex_name, :content => content) unless content.blank? else result << tag(:meta, :name => noindex_name, :content => 'noindex') if [:noindex] result << tag(:meta, :name => nofollow_name, :content => 'nofollow') if [:nofollow] end # canonical result << tag(:link, :rel => :canonical, :href => [:canonical]) unless [:canonical].blank? result = result.join("\n") result.respond_to?(:html_safe) ? result.html_safe : result end |