Module: Sitemapper::Helpers
- Defined in:
- lib/sitemapper/helpers.rb
Instance Method Summary collapse
-
#page_meta ⇒ Object
Returns the meta tags for the current page, for example:.
-
#page_with_object(obj) ⇒ Object
(also: #page)
:nodoc:.
-
#title(title, opts = {}) ⇒ Object
Returns the title of the page with the website title.
Instance Method Details
#page_meta ⇒ Object
Returns the meta tags for the current page, for example:
app/views/foo/.html.erb
page(:title => 'Foo bar!',
:description => 'Lorem ipsum dollar sit amet',
:keywords => 'lorem, ipsum dollar, sit, amet')
app/views/layouts/application.html.erb
...
<head>
<%= title('My Webste') %>
<%= %>
</head>
...
The example above will output the following on the rendered page:
...
<head>
<title>Foo :: My Website</title>
<meta name="description" content="Lorem ipsum dollar sit amet" />
< name="keywords" content="lore, ipsum dollar, sit, amet" />
</head>
83 84 85 86 87 88 |
# File 'lib/sitemapper/helpers.rb', line 83 def res = '' res << tag(:meta, :name => 'description', :content => @_desc) if @_desc res << tag(:meta, :name => 'keywords', :content => @_keys) if @_desc return res end |
#page_with_object(obj) ⇒ Object Also known as: page
:nodoc:
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sitemapper/helpers.rb', line 24 def page_with_object(obj) # :nodoc: obj = begin lookup = Sitemapper..merge(obj.class.sitemapper_config || {}) defs = {} [:title, :desc, :keywords].each do |key| method = lookup[key] method = method.find {|m| obj.respond_to?(m)} if method.is_a?(Array) defs[key] = method.nil?? nil : obj.send(method) end # Do you think it's ugly? You have to see my grandma in underwear defs end unless obj.is_a?(Hash) return page_without_object(obj) end |
#title(title, opts = {}) ⇒ Object
Returns the title of the page with the website title
Parameters
-
the first parameter is the website title
-
the second parameter is a options hash:
-
:separatoris the separator of the page and the website title
-
See page_meta for further information and examples.
52 53 54 55 |
# File 'lib/sitemapper/helpers.rb', line 52 def title(title, opts={}) separator = opts[:separator] || ' :: ' content_tag(:title, @_title.nil?? title : "#{@_title}#{separator}#{title}") end |