Module: Storefront::Helpers::HeadHelper

Defined in:
lib/storefront/helpers/head_helper.rb

Instance Method Summary collapse

Instance Method Details

#apple_full_screen_meta_tag(value) ⇒ Object



229
230
231
# File 'lib/storefront/helpers/head_helper.rb', line 229

def apple_full_screen_meta_tag(value)
  meta_tag("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 apple_meta_tags(options = {})
  result = []
  result << apple_viewport_meta_tag(options)
  result << apple_full_screen_meta_tag(options[:full_screen]) if options.has_key?(:full_screen)
  result << apple_mobile_compatible_meta_tag(options[:mobile]) if options.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 apple_mobile_compatible_meta_tag(value)
  meta_tag("apple-mobile-web-app-capable", value == true ? "yes" : "no")
end


237
238
239
240
241
242
# File 'lib/storefront/helpers/head_helper.rb', line 237

def apple_touch_icon_link_tag(path, options = {})
  rel = ["apple-touch-icon"]
  rel << "#{options[:size]}x#{options[:size]}" if options[:size].present?
  rel << "precomposed" if options[:precomposed]
  link_tag(:rel => rel.join("-"), :href => path)
end


244
245
246
247
# File 'lib/storefront/helpers/head_helper.rb', line 244

def apple_touch_icon_link_tags(path, *sizes)
  options = sizes.extract_options!
  sizes.map { |size| apple_touch_icon_link_tag(path, options.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 apple_viewport_meta_tag(options = {})
  viewport = []
  viewport << "width=#{options[:width]}" if options[:width].present?
  viewport << "height=#{options[:height]}" if options[:height].present?
  viewport << "initial-scale=#{options[:scale] || 1.0}"
  viewport << "minimum-scale=#{options[:min]}" if options[:min].present?
  viewport << "maximum-scale=#{options[:max]}" if options[:max].present?
  viewport << "user-scalable=#{options[:scalable] == true ? "yes" : "no"}" if options.has_key?(:scalable)
  
  meta_tag("viewport", viewport.join(", "))
end


136
137
138
# File 'lib/storefront/helpers/head_helper.rb', line 136

def canonical_link_tag(path)
  link_tag(:rel => :canonical, :href => path)
end


97
98
99
# File 'lib/storefront/helpers/head_helper.rb', line 97

def copyright(string)
  @content_for_copyright = string
end


101
102
103
104
# File 'lib/storefront/helpers/head_helper.rb', line 101

def copyright_tag(default='')
  content = @content_for_copyright || default
  meta_tag(: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)
  meta_tag(:description, content) unless content.blank?
end


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")
  http_meta_tag("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 http_meta_tag(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 ie_application_meta_tags(title, options = {})
  result = []
  result << meta_tag("application-name", title)
  result << meta_tag("msapplication-tooltip", options[:tooltip]) if options[:tooltip].present?
  result << meta_tag("msapplication-starturl", options[:url]) if options[:url].present?
  if options[:width].present? && options[:height].present?
    result << meta_tag("msapplication-window", "width=#{options[:width]};height=#{options[:height]}")
  end
  result << meta_tag("msapplication-navbutton-color", options[:color]) if options[: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 ie_task_meta_tag(name, path, icon = nil)
  content = []
  content << "name=#{name}"
  content << "uri=#{path}"
  content << "icon-uri=#{icon}" if icon
  meta_tag("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)
  meta_tag(:keywords, content) unless content.blank?
end


184
185
186
# File 'lib/storefront/helpers/head_helper.rb', line 184

def link_tag(options = {})
  capture_haml { haml_tag :link, options }
end

#meta_tag(name, content = '') ⇒ Object



17
18
19
# File 'lib/storefront/helpers/head_helper.rb', line 17

def meta_tag(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 meta_tags(*args)
  options = args.extract_options!
  options[:site] ||= args.shift
  result = []
  storefront_config.meta_tags.each do |meta_tag_name|
    if options[meta_tag_name].present?
      result << meta_tag(meta_tag_name, options[meta_tag_name])
    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 open_graph_meta_tag(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 open_graph_meta_tags(options = {})
  result = []
  
  result << open_graph_meta_tag("og:title", options[:title]) if options[:title]
  result << open_graph_meta_tag("og:type", options[:type]) if options[:type]
  result << open_graph_meta_tag("og:image", options[:image]) if options[:image]
  result << open_graph_meta_tag("og:site_name", options[:site]) if options[:site]
  result << open_graph_meta_tag("og:description", options[:description]) if options[:description]
  result << open_graph_meta_tag("og:email", options[:email]) if options[:email]
  result << open_graph_meta_tag("og:phone_number", options[:phone]) if options[:phone]
  result << open_graph_meta_tag("og:fax_number", options[:fax]) if options[:fax]
  result << open_graph_meta_tag("og:latitude", options[:lat]) if options[:lat]
  result << open_graph_meta_tag("og:longitude", options[:lng]) if options[:lng]
  result << open_graph_meta_tag("og:street-address", options[:street]) if options[:street]
  result << open_graph_meta_tag("og:locality", options[:city]) if options[:city]
  result << open_graph_meta_tag("og:region", options[:state]) if options[:state]
  result << open_graph_meta_tag("og:postal-code", options[:zip]) if options[:zip]
  result << open_graph_meta_tag("og:country-name", options[:country]) if options[: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 pagination_meta_tags(options = {})
  
end

#refresh_meta_tag(path, options = {}) ⇒ Object

Examples:

Redirect to the site home page in 20 seconds.


refresh_meta_tag root_url, :in => 20.seconds


147
148
149
# File 'lib/storefront/helpers/head_helper.rb', line 147

def refresh_meta_tag(path, options = {})
  http_meta_tag("refresh", "#{options[: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)
  options = args.extract_options!
    
  noindex_name = tags[:noindex].is_a?(String) ? tags[:noindex] : 'robots'
  nofollow_name = tags[:nofollow].is_a?(String) ? tags[:nofollow] : 'robots'

  if noindex_name == nofollow_name
    content = [(tags[:noindex] ? 'noindex' : nil), (tags[:nofollow] ? 'nofollow' : nil)].compact.join(', ')
    unless content.blank?
      result << "\n"
      result << meta_tag(noindex_name, content)
    end
  else
    if tags[:noindex]
      result << "\n"
      result << meta_tag(noindex_name, "noindex")
    end
    if tags[:nofollow]
      result << "\n"
      result << meta_tag(nofollow_name, "nofollow")
    end
  end

  return result
end


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


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)
  options = args.extract_options!
  # Title
  title   = @content_for_title

  if title.present?
    options.merge!(title.extract_options!)
    title = @content_for_title.shift || options[:title]
  end

  if options[:lowercase] === true
    title = title.downcase unless title.blank?
  end

  site    = options.has_key?(:site) ? options[:site] : args.first

  # Prefix (leading space)
  if options[:prefix]
    prefix = options[:prefix]
  elsif options[:prefix] === false
    prefix = ''
  else
    prefix = ' '
  end

  # Separator
  unless options[:separator].blank?
    separator = options[:separator]
  else
    separator = '|'
  end

  # Suffix (trailing space)
  if options[:suffix]
    suffix = options[:suffix]
  elsif options[:suffix] === false
    suffix = ''
  else
    suffix = ' '
  end

  # title
  if title.blank?
    result =  :title, site
  else
    title  = normalize_title(title)
    title  = [site] + title if site
    title.reverse! unless options[:reverse] === false
    sep    = prefix + separator + suffix
    result = (:title, title.join(sep))
  end
  result
end