Module: Represent::HeadHelper
- Defined in:
- lib/represent/head_helper.rb
Instance Method Summary collapse
- #classification(type) ⇒ Object
- #content_type_tag(type = "text/html", charset = "UTF-8") ⇒ Object
- #copyright(from) ⇒ Object
- #copyright_tag(default = '') ⇒ Object
- #description(string) ⇒ Object
- #description_tag(default = '') ⇒ Object
- #favicon_link_tag(favicon = "/favicon.ico") ⇒ Object
- #keywords(string) ⇒ Object
- #keywords_tag(default = '') ⇒ Object
- #link_tag(options = {}) ⇒ Object
- #medium(type) ⇒ Object
- #meta(options = {}) ⇒ Object
-
#meta_tag(name, content = '') ⇒ Object
country classification author apple-mobile-web-app-capable apple-touch-fullscreen google-analytics Revisit-After category.
- #meta_tags(*args) ⇒ Object
- #robots(*args) ⇒ Object
- #robots_tag(*args) ⇒ Object
- #search_link_tag(href, title) ⇒ Object
- #snapshot_tag(href) ⇒ Object
- #title(string) ⇒ Object
- #title_tag(*args) ⇒ Object
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") ("Content-Type", "#{type}; charset=#{charset}") end |
#copyright(from) ⇒ Object
108 109 110 |
# File 'lib/represent/head_helper.rb', line 108 def copyright(string) @content_for_copyright = string end |
#copyright_tag(default = '') ⇒ Object
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 |
#favicon_link_tag(favicon = "/favicon.ico") ⇒ Object
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 |
#link_tag(options = {}) ⇒ Object
189 190 191 |
# File 'lib/represent/head_helper.rb', line 189 def link_tag( = {}) tag(:link, ) 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 ( = {}) title([:title]) if .has_key?(:title) description([:description]) if .has_key?(:description) keywords([:keywords]) if .has_key?(:keywords) copyright([:copyright]) if .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 (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 (*args) = args. site = [:site] || args.first result = title_tag(site, [:title]) result << "\n" result << content_type_tag result << "\n" result << description_tag([:description]) result << "\n" result << keywords_tag([:keywords]) result << "\n" result << copyright_tag([: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) = 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 << tag(:meta, :name => noindex_name, :content => content) end else if [:noindex] result << "\n" result << tag(:meta, :name => noindex_name, :content => 'noindex') end if [:nofollow] result << "\n" result << tag(:meta, :name => nofollow_name, :content => 'nofollow') end end # canonical unless [:canonical].blank? result << "\n" result << tag(:link, :rel => :canonical, :href => [:canonical]) end return result end |
#search_link_tag(href, title) ⇒ Object
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) = args. 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 title = @content_for_title if [:lowercase] === true title = title.downcase unless title.blank? end # 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 result end |