Module: Facades::Helpers::Layout
- Included in:
- Facades::Helpers
- Defined in:
- lib/facades/helpers/layout.rb
Overview
Convenience helpers generally used in layout files
Instance Method Summary collapse
-
#browser_name ⇒ Object
Returns a short-hand string identifying the current browser.
-
#google_analytics(site_id, &block) ⇒ String
Create a script tag for activating google analytics.
-
#meta_tag(name, content) ⇒ String
Allows easy assigning of meta tags from templates.
-
#page_id(content = nil) ⇒ String
Creates a page id to be used for identifying a page for CSS/design purposes.
-
#page_title(content = nil) ⇒ String
Convenience method to create a page title for the <title></title> tag.
-
#robot_meta_tag ⇒ String
Configures a “robots” meta tag based on the rails environment.
Instance Method Details
#browser_name ⇒ Object
Returns a short-hand string identifying the current browser
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/facades/helpers/layout.rb', line 10 def browser_name uastr = request.user_agent.to_s return "webkit" if uastr =~ /(webkit)[ \/]([\w.]+)/i return "opera" if uastr =~ /(opera)(?:.*version)?[ \/]([\w.]+)/i if matches = uastr.match(/(msie) ([\w.]+)/i) version = (matches[2]||0).to_i return "ie#{version}" end return "mozilla" if uastr =~ /(mozilla)(?:.*? rv:([\w.]+))?/i "unknown" end |
#google_analytics(site_id, &block) ⇒ String
Create a script tag for activating google analytics
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/facades/helpers/layout.rb', line 38 def google_analytics(site_id, &block) return "" if defined?(Rails) && Rails.env != "production" content_tag(:script) do %Q{ var _gaq=[['_setAccount','#{site_id}'],['_trackPageview']]; (function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0]; g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js'; s.parentNode.insertBefore(g,s)}(document,'script')); #{(block_given? ? capture(&block) : "")} } end.html_safe end |
#meta_tag(name, content) ⇒ String
Allows easy assigning of meta tags from templates
29 30 31 |
# File 'lib/facades/helpers/layout.rb', line 29 def (name, content) tag(:meta, :name => name, :content => content) end |
#page_id(content = nil) ⇒ String
Creates a page id to be used for identifying a page for CSS/design purposes. If a variable is defined, it will be used. If not, one will be generated from the current controller/action.
68 69 70 71 |
# File 'lib/facades/helpers/layout.rb', line 68 def page_id(content = nil) return (@view_flow.get(:page_id) || default_page_title_for_view) unless content provide(:page_id, content) if content end |
#page_title(content = nil) ⇒ String
Convenience method to create a page title for the <title></title> tag.
85 86 87 88 89 |
# File 'lib/facades/helpers/layout.rb', line 85 def page_title(content = nil) provide(:page_title, content) and return if content return @view_flow.get(:page_title) unless content "" end |
#robot_meta_tag ⇒ String
Configures a “robots” meta tag based on the rails environment. In environments other than ‘production’ it sets the value to “noindex, nofollow” for each page that uses the layout in which it is called. This helps prevent spiders from crawling / indexing content when used on staging sites.
99 100 101 |
# File 'lib/facades/helpers/layout.rb', line 99 def tag(:meta, :name => 'robots', :content => (Rails.env.eql?('production') ? 'index, follow' : 'noindex, nofollow')) end |