Module: Insightful::HeadHelper

Defined in:
lib/insightful/head_helper.rb

Instance Method Summary collapse

Instance Method Details

#classification(type) ⇒ Object



190
191
192
# File 'lib/insightful/head_helper.rb', line 190

def classification(type)
  tag(:meta, :name => "og:type", :content => type)
end

#content_type_tag(type = "text/html", charset = "UTF-8") ⇒ Object



194
195
196
# File 'lib/insightful/head_helper.rb', line 194

def content_type_tag(type = "text/html", charset = "UTF-8")
  meta_tag("Content-Type", "#{type}; charset=#{charset}")
end


125
126
127
# File 'lib/insightful/head_helper.rb', line 125

def copyright(string)
  @content_for_copyright = string
end


129
130
131
132
# File 'lib/insightful/head_helper.rb', line 129

def copyright_tag(default='')
  content = @content_for_copyright || default
  tag(:meta, :name => :copyright, :content => content) unless content.blank?
end

#description(string) ⇒ Object



107
108
109
# File 'lib/insightful/head_helper.rb', line 107

def description(string)
  @content_for_description = string
end

#description_tag(default = '') ⇒ Object



111
112
113
114
# File 'lib/insightful/head_helper.rb', line 111

def description_tag(default='')
  content = normalize_description(@content_for_description || default)
  tag(:meta, :name => :description, :content => content) unless content.blank?
end


202
203
204
# File 'lib/insightful/head_helper.rb', line 202

def favicon_link_tag(favicon = "/favicon.ico")
  link_tag({:rel => "shortcut icon", :href => favicon, :type => "image/x-icon"})
end

#keywords(string) ⇒ Object



116
117
118
# File 'lib/insightful/head_helper.rb', line 116

def keywords(string)
  @content_for_keywords = string
end

#keywords_tag(default = '') ⇒ Object



120
121
122
123
# File 'lib/insightful/head_helper.rb', line 120

def keywords_tag(default = '')
  content = normalize_keywords(@content_for_keywords || default)
  tag(:meta, :name => :keywords, :content => content) unless content.blank?
end


206
207
208
# File 'lib/insightful/head_helper.rb', line 206

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

#medium(type) ⇒ Object



186
187
188
# File 'lib/insightful/head_helper.rb', line 186

def medium(type)
  tag(:meta, :name => :medium, :content => type)
end

#meta(options = {}) ⇒ Object



21
22
23
24
25
26
# File 'lib/insightful/head_helper.rb', line 21

def meta(options = {})
  title(options[:title]) if options.has_key?(:title)
  description(options[:description]) if options.has_key?(:description)
  keywords(options[:keywords]) if options.has_key?(:keywords)
  copyright(options[:copyright]) if options.has_key?(:copyright)
end

#meta_for(post) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/insightful/head_helper.rb', line 4

def meta_for(post)
  result = ""
  unless post.title.blank?
    result << title(post.title)
    result << "\n"
  end
  unless post.tags.blank?
    result << keywords(post.tags.join(", "))
    result << "\n"
  end
  unless post.description.blank?
    result << description(post.description)
    result << "\n"
  end
  result
end

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

country classification author apple-mobile-web-app-capable apple-touch-fullscreen google-analytics Revisit-After category



51
52
53
# File 'lib/insightful/head_helper.rb', line 51

def meta_tag(name, content = '')
  tag(:meta, :name => name, :content => content)
end

#meta_tags(*args) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/insightful/head_helper.rb', line 28

def meta_tags(*args)
  options = args.extract_options!
  site = options[:site] || args.first
  result = title_tag(site, options[:title])
  result << "\n"
  result << content_type_tag
  result << "\n"
  result << description_tag(options[:description])
  result << "\n"
  result << keywords_tag(options[:keywords])
  result << "\n"
  result << copyright_tag(options[:copyright])
  result
end

#robots(*args) ⇒ Object



134
135
136
# File 'lib/insightful/head_helper.rb', line 134

def robots(*args)
  content_for(:robots, args.join(", "))
end

#robots_tag(*args) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/insightful/head_helper.rb', line 138

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 << tag(:meta, :name => noindex_name, :content => content)
    end
  else
    if tags[:noindex]
      result << "\n"
      result << tag(:meta, :name => noindex_name, :content => 'noindex')
    end
    if tags[:nofollow]
      result << "\n"
      result << tag(:meta, :name => nofollow_name, :content => 'nofollow')
    end
  end
  # canonical
  unless tags[:canonical].blank?
    result << "\n"
    result << tag(:link, :rel => :canonical, :href => tags[:canonical]) 
  end

  return result
end


198
199
200
# File 'lib/insightful/head_helper.rb', line 198

def search_link_tag(href, title)
  link_tag({:rel => "search", :type => "application/opensearchdescription+xml", :href => href, :title => title})
end

#snapshot_tag(href) ⇒ Object



181
182
183
# File 'lib/insightful/head_helper.rb', line 181

def snapshot_tag(href)
  tag(:link, :rel => "image_src", :href => href)
end

#title(string) ⇒ Object



55
56
57
# File 'lib/insightful/head_helper.rb', line 55

def title(string)
  @content_for_title = string
end

#title_tag(*args) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/insightful/head_helper.rb', line 59

def title_tag(*args)
  options = args.extract_options!

  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
  title = @content_for_title
  if options[:lowercase] === true
    title = title.downcase unless title.blank?
  end

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