Module: Storefront::Helpers::HeadHelper
- Defined in:
- lib/storefront/helpers/head_helper.rb
Instance Method Summary collapse
- #apple_full_screen_meta_tag(value) ⇒ Object
- #apple_meta_tags(options = {}) ⇒ Object
- #apple_mobile_compatible_meta_tag(value) ⇒ Object
- #apple_touch_icon_link_tag(path, options = {}) ⇒ Object
- #apple_touch_icon_link_tags(path, *sizes) ⇒ Object
- #apple_viewport_meta_tag(options = {}) ⇒ Object
- #canonical_link_tag(path) ⇒ Object
- #copyright(from) ⇒ Object
- #copyright_tag(default = '') ⇒ Object
- #description(string) ⇒ Object
- #description_tag(default = '') ⇒ Object
- #favicon_link_tag(favicon = "/favicon.ico") ⇒ Object
- #html4_content_type_tag(charset = "UTF-8", type = "text/html") ⇒ Object
- #html5_content_type_tag(charset = "UTF-8") ⇒ Object (also: #content_type_tag)
- #http_meta_tag(name, content) ⇒ Object
- #ie_application_meta_tags(title, options = {}) ⇒ Object
- #ie_task_meta_tag(name, path, icon = nil) ⇒ Object
- #keywords(string) ⇒ Object
- #keywords_tag(default = '') ⇒ Object
- #link_tag(options = {}) ⇒ Object
- #meta_tag(name, content = '') ⇒ Object
- #meta_tags(*args) ⇒ Object (also: #meta)
- #open_graph_meta_tag(property, content) ⇒ Object
- #open_graph_meta_tags(options = {}) ⇒ Object
-
#pagination_meta_tags(options = {}) ⇒ Object
first, last, next, prev.
- #refresh_meta_tag(path, options = {}) ⇒ Object
- #robots(*args) ⇒ Object
- #robots_tag(*args) ⇒ Object
- #search_link_tag(href, title) ⇒ Object
- #snapshot_link_tag(href) ⇒ Object
- #title(*args) ⇒ Object
- #title_tag(*args) ⇒ Object
Instance Method Details
#apple_full_screen_meta_tag(value) ⇒ Object
229 230 231 |
# File 'lib/storefront/helpers/head_helper.rb', line 229 def (value) ("apple-touch-fullscreen", value == true ? "yes" : "no") end |
#apple_meta_tags(options = {}) ⇒ Object
208 209 210 211 212 213 214 |
# File 'lib/storefront/helpers/head_helper.rb', line 208 def ( = {}) result = [] result << () result << ([:full_screen]) if .has_key?(:full_screen) result << ([:mobile]) if .has_key?(:mobile) result.join end |
#apple_mobile_compatible_meta_tag(value) ⇒ Object
233 234 235 |
# File 'lib/storefront/helpers/head_helper.rb', line 233 def (value) ("apple-mobile-web-app-capable", value == true ? "yes" : "no") end |
#apple_touch_icon_link_tag(path, options = {}) ⇒ Object
237 238 239 240 241 242 |
# File 'lib/storefront/helpers/head_helper.rb', line 237 def apple_touch_icon_link_tag(path, = {}) rel = ["apple-touch-icon"] rel << "#{[:size]}x#{[:size]}" if [:size].present? rel << "precomposed" if [:precomposed] link_tag(:rel => rel.join("-"), :href => path) end |
#apple_touch_icon_link_tags(path, *sizes) ⇒ Object
244 245 246 247 |
# File 'lib/storefront/helpers/head_helper.rb', line 244 def (path, *sizes) = sizes. sizes.map { |size| apple_touch_icon_link_tag(path, .merge(:size => size)) }.join end |
#apple_viewport_meta_tag(options = {}) ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/storefront/helpers/head_helper.rb', line 217 def ( = {}) = [] << "width=#{[:width]}" if [:width].present? << "height=#{[:height]}" if [:height].present? << "initial-scale=#{[:scale] || 1.0}" << "minimum-scale=#{[:min]}" if [:min].present? << "maximum-scale=#{[:max]}" if [:max].present? << "user-scalable=#{[:scalable] == true ? "yes" : "no"}" if .has_key?(:scalable) ("viewport", .join(", ")) end |
#canonical_link_tag(path) ⇒ Object
136 137 138 |
# File 'lib/storefront/helpers/head_helper.rb', line 136 def canonical_link_tag(path) link_tag(:rel => :canonical, :href => path) end |
#copyright(from) ⇒ Object
97 98 99 |
# File 'lib/storefront/helpers/head_helper.rb', line 97 def copyright(string) @content_for_copyright = string end |
#copyright_tag(default = '') ⇒ Object
101 102 103 104 |
# File 'lib/storefront/helpers/head_helper.rb', line 101 def copyright_tag(default='') content = @content_for_copyright || default (:copyright, content) unless content.blank? end |
#description(string) ⇒ Object
79 80 81 |
# File 'lib/storefront/helpers/head_helper.rb', line 79 def description(string) @content_for_description = string end |
#description_tag(default = '') ⇒ Object
83 84 85 86 |
# File 'lib/storefront/helpers/head_helper.rb', line 83 def description_tag(default='') content = normalize_description(@content_for_description || default) (:description, content) unless content.blank? end |
#favicon_link_tag(favicon = "/favicon.ico") ⇒ Object
180 181 182 |
# File 'lib/storefront/helpers/head_helper.rb', line 180 def favicon_link_tag(favicon = "/favicon.ico") link_tag(:rel => "shortcut icon", :href => favicon, :type => "image/x-icon") end |
#html4_content_type_tag(charset = "UTF-8", type = "text/html") ⇒ Object
167 168 169 |
# File 'lib/storefront/helpers/head_helper.rb', line 167 def html4_content_type_tag(charset = "UTF-8", type = "text/html") ("Content-Type", "#{type}; charset=#{charset}") end |
#html5_content_type_tag(charset = "UTF-8") ⇒ Object Also known as: content_type_tag
171 172 173 |
# File 'lib/storefront/helpers/head_helper.rb', line 171 def html5_content_type_tag(charset = "UTF-8") capture_haml { haml_tag :meta, "charset" => charset } end |
#http_meta_tag(name, content) ⇒ Object
140 141 142 |
# File 'lib/storefront/helpers/head_helper.rb', line 140 def (name, content) capture_haml { haml_tag :meta, :"http-equiv" => name, :content => content } end |
#ie_application_meta_tags(title, options = {}) ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/storefront/helpers/head_helper.rb', line 188 def (title, = {}) result = [] result << ("application-name", title) result << ("msapplication-tooltip", [:tooltip]) if [:tooltip].present? result << ("msapplication-starturl", [:url]) if [:url].present? if [:width].present? && [:height].present? result << ("msapplication-window", "width=#{[:width]};height=#{[:height]}") end result << ("msapplication-navbutton-color", [:color]) if [:color].present? result.join("\n") end |
#ie_task_meta_tag(name, path, icon = nil) ⇒ Object
200 201 202 203 204 205 206 |
# File 'lib/storefront/helpers/head_helper.rb', line 200 def (name, path, icon = nil) content = [] content << "name=#{name}" content << "uri=#{path}" content << "icon-uri=#{icon}" if icon ("msapplication-task", content.join(";")) end |
#keywords(string) ⇒ Object
88 89 90 |
# File 'lib/storefront/helpers/head_helper.rb', line 88 def keywords(string) @content_for_keywords = string end |
#keywords_tag(default = '') ⇒ Object
92 93 94 95 |
# File 'lib/storefront/helpers/head_helper.rb', line 92 def keywords_tag(default = '') content = normalize_keywords(@content_for_keywords || default) (:keywords, content) unless content.blank? end |
#link_tag(options = {}) ⇒ Object
184 185 186 |
# File 'lib/storefront/helpers/head_helper.rb', line 184 def link_tag( = {}) capture_haml { haml_tag :link, } end |
#meta_tag(name, content = '') ⇒ Object
17 18 19 |
# File 'lib/storefront/helpers/head_helper.rb', line 17 def (name, content = '') capture_haml { haml_tag :meta, :name => name, :content => content } end |
#meta_tags(*args) ⇒ Object Also known as: meta
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/storefront/helpers/head_helper.rb', line 4 def (*args) = args. [:site] ||= args.shift result = [] storefront_config..each do || if [].present? result << (, []) end end result.join("\n") end |
#open_graph_meta_tag(property, content) ⇒ Object
271 272 273 |
# File 'lib/storefront/helpers/head_helper.rb', line 271 def (property, content) capture_haml { haml_tag :meta, :property => property, :content => content } end |
#open_graph_meta_tags(options = {}) ⇒ Object
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/storefront/helpers/head_helper.rb', line 249 def ( = {}) result = [] result << ("og:title", [:title]) if [:title] result << ("og:type", [:type]) if [:type] result << ("og:image", [:image]) if [:image] result << ("og:site_name", [:site]) if [:site] result << ("og:description", [:description]) if [:description] result << ("og:email", [:email]) if [:email] result << ("og:phone_number", [:phone]) if [:phone] result << ("og:fax_number", [:fax]) if [:fax] result << ("og:latitude", [:lat]) if [:lat] result << ("og:longitude", [:lng]) if [:lng] result << ("og:street-address", [:street]) if [:street] result << ("og:locality", [:city]) if [:city] result << ("og:region", [:state]) if [:state] result << ("og:postal-code", [:zip]) if [:zip] result << ("og:country-name", [:country]) if [:country] result.join("\n") end |
#pagination_meta_tags(options = {}) ⇒ Object
first, last, next, prev
276 277 278 |
# File 'lib/storefront/helpers/head_helper.rb', line 276 def ( = {}) end |
#refresh_meta_tag(path, options = {}) ⇒ Object
147 148 149 |
# File 'lib/storefront/helpers/head_helper.rb', line 147 def (path, = {}) ("refresh", "#{[:in].to_i};url=#{path}") end |
#robots(*args) ⇒ Object
106 107 108 |
# File 'lib/storefront/helpers/head_helper.rb', line 106 def robots(*args) content_for(:robots, args.join(", ")) end |
#robots_tag(*args) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/storefront/helpers/head_helper.rb', line 110 def robots_tag(*args) = args. 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(', ') unless content.blank? result << "\n" result << (noindex_name, content) end else if [:noindex] result << "\n" result << (noindex_name, "noindex") end if [:nofollow] result << "\n" result << (nofollow_name, "nofollow") end end return result end |
#search_link_tag(href, title) ⇒ Object
176 177 178 |
# File 'lib/storefront/helpers/head_helper.rb', line 176 def search_link_tag(href, title) link_tag(:rel => "search", :type => "application/opensearchdescription+xml", :href => href, :title => title) end |
#snapshot_link_tag(href) ⇒ Object
163 164 165 |
# File 'lib/storefront/helpers/head_helper.rb', line 163 def snapshot_link_tag(href) link_tag(:rel => "image_src", :href => href) end |
#title(*args) ⇒ Object
21 22 23 |
# File 'lib/storefront/helpers/head_helper.rb', line 21 def title(*args) @content_for_title = *args end |
#title_tag(*args) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/storefront/helpers/head_helper.rb', line 25 def title_tag(*args) = args. # Title title = @content_for_title if title.present? .merge!(title.) title = @content_for_title.shift || [:title] end if [:lowercase] === true title = title.downcase unless title.blank? end site = .has_key?(:site) ? [:site] : args.first # Prefix (leading space) if [:prefix] prefix = [:prefix] elsif [:prefix] === false prefix = '' else prefix = ' ' end # Separator unless [:separator].blank? separator = [:separator] else separator = '|' end # Suffix (trailing space) if [:suffix] suffix = [:suffix] elsif [:suffix] === false suffix = '' else suffix = ' ' end # title if title.blank? result = content_tag :title, site else title = normalize_title(title) title = [site] + title if site title.reverse! unless [:reverse] === false sep = prefix + separator + suffix result = content_tag(:title, title.join(sep)) end result end |