Module: Sitemapper::Helpers

Defined in:
lib/sitemapper/helpers.rb

Instance Method Summary collapse

Instance Method Details

#page_metaObject

Returns the meta tags for the current page, for example:

app/views/foo/bar.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') %>
    <%= page_meta %>
</head>
...

The example above will output the following on the rendered page:

...
<head>
    <title>Foo bar! :: My Website</title>
    <meta name="description" content="Lorem ipsum dollar sit amet" />
    <meta name="keywords" content="lore, ipsum dollar, sit, amet" />
</head>


83
84
85
86
87
88
# File 'lib/sitemapper/helpers.rb', line 83

def page_meta
  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.meta_lookup.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:

    • :separator is 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] || ' :: '
  (:title, @_title.nil?? title : "#{@_title}#{separator}#{title}")
end