Module: Sitemapper::Helpers

Defined in:
lib/sitemapper/helpers.rb

Instance Method Summary collapse

Instance Method Details

#page(defs) ⇒ Object

Set the page data for title and meta tags

Parameters

  • :title the title of the page
  • :desc the description of the current page
  • :keywords the keywords that represent the current page

The parameter can also be an object that respond to (used preferentially on this order):

  • title OR name (for title)
  • short_description OR description (for description)
  • tag_list OR keywords (for keywords)

See page_meta for further information and examples.



17
18
19
20
21
# File 'lib/sitemapper/helpers.rb', line 17

def page(defs)
  @_title = defs.delete(:title)
  @_desc  = defs.delete(:desc)
  @_keys  = defs.delete(:keywords)
end

#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>


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

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

:nodoc:



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

def page_with_object(defs) # :nodoc:
  return page_without_object(defs) if defs.is_a?(Hash)
  @_title = if defs.respond_to?(:title)
    defs.title
  elsif defs.respond_to?(:name)
    defs.name
  end
  @_desc  = if defs.respond_to?(:short_description)
    defs.short_description
  elsif defs.respond_to?(:description)
    defs.description
  end
  @_keys  = if defs.respond_to?(:tag_list)
    defs.tag_list
  elsif defs.respond_to?(:keywords)
    defs.keywords
  end
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.



53
54
55
56
# File 'lib/sitemapper/helpers.rb', line 53

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