Module: Sitemapper::Helpers

Defined in:
lib/sitemapper/helpers.rb

Instance Method Summary collapse

Instance Method Details

#page_meta ⇒ Object

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>


87
88
89
90
91
92
# File 'lib/sitemapper/helpers.rb', line 87

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(defs) ⇒ Object Also known as: page

:nodoc:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/sitemapper/helpers.rb', line 24

def page_with_object(defs) # :nodoc:
  return page_without_object(defs) if defs.is_a?(Hash)

  lookup_method = lambda do |obj, key|
    methods = obj.class.respond_to?(:sitemapper_config)? obj.class.sitemapper_config : Sitemapper.meta_lookup
    methods = methods[key]
    method = if methods.is_a?(Array)
      methods.find {|m| obj.respond_to?(m)}
    elsif methods.is_a?(String) || methods.is_a?(Symbol)
      methods
    end
    logger.debug(">>> #{method}")
    return method.nil?? nil : obj.send(method)
  end # Do you think it's ugly? You have to see my grandma in underwear

  @_title = lookup_method.call(defs, :title)
  @_desc  = lookup_method.call(defs, :desc)
  @_keys  = lookup_method.call(defs, :keywords)
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.



56
57
58
59
# File 'lib/sitemapper/helpers.rb', line 56

def title(title, opts={})
  separator = opts[:separator] || ' :: '
  (:title, @_title.nil?? title : "#{@_title}#{separator}#{title}")
end