Module: Insightful::HeadHelper
- Defined in:
- lib/insightful/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_for(post) ⇒ 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
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") ("Content-Type", "#{type}; charset=#{charset}") end |
#copyright(from) ⇒ Object
125 126 127 |
# File 'lib/insightful/head_helper.rb', line 125 def copyright(string) @content_for_copyright = string end |
#copyright_tag(default = '') ⇒ Object
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 |
#favicon_link_tag(favicon = "/favicon.ico") ⇒ Object
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 |
#link_tag(options = {}) ⇒ Object
206 207 208 |
# File 'lib/insightful/head_helper.rb', line 206 def link_tag( = {}) tag(:link, ) 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 ( = {}) 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_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 (post) result = "" unless post.title.blank? result << title(post.title) result << "\n" end unless post..blank? result << keywords(post..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 (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 (*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
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) = 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
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) = 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! unless [:reverse] === false sep = prefix + separator + suffix result = content_tag(:title, title.join(sep)) end result end |