Module: Represent::HeadHelper

Defined in:
lib/represent/head_helper.rb

Instance Method Summary collapse

Instance Method Details

#classification(type) ⇒ Object



173
174
175
# File 'lib/represent/head_helper.rb', line 173

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

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



177
178
179
# File 'lib/represent/head_helper.rb', line 177

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


108
109
110
# File 'lib/represent/head_helper.rb', line 108

def copyright(string)
  @content_for_copyright = string
end


112
113
114
115
# File 'lib/represent/head_helper.rb', line 112

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

#description(string) ⇒ Object



90
91
92
# File 'lib/represent/head_helper.rb', line 90

def description(string)
  @content_for_description = string
end

#description_tag(default = '') ⇒ Object



94
95
96
97
# File 'lib/represent/head_helper.rb', line 94

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


185
186
187
# File 'lib/represent/head_helper.rb', line 185

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

#keywords(string) ⇒ Object



99
100
101
# File 'lib/represent/head_helper.rb', line 99

def keywords(string)
  @content_for_keywords = string
end

#keywords_tag(default = '') ⇒ Object



103
104
105
106
# File 'lib/represent/head_helper.rb', line 103

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


189
190
191
# File 'lib/represent/head_helper.rb', line 189

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

#medium(type) ⇒ Object



169
170
171
# File 'lib/represent/head_helper.rb', line 169

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

#meta(options = {}) ⇒ Object



4
5
6
7
8
9
# File 'lib/represent/head_helper.rb', line 4

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_tag(name, content = '') ⇒ Object

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



34
35
36
# File 'lib/represent/head_helper.rb', line 34

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

#meta_tags(*args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/represent/head_helper.rb', line 11

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



117
118
119
# File 'lib/represent/head_helper.rb', line 117

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

#robots_tag(*args) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/represent/head_helper.rb', line 121

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


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

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

#snapshot_tag(href) ⇒ Object



164
165
166
# File 'lib/represent/head_helper.rb', line 164

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

#title(string) ⇒ Object



38
39
40
# File 'lib/represent/head_helper.rb', line 38

def title(string)
  @content_for_title = string
end

#title_tag(*args) ⇒ Object



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
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/represent/head_helper.rb', line 42

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! if options[:reverse] === true
    sep = prefix + separator + suffix
    result = (:title, title.join(sep))
  end
  result
end