Module: Helperful::TitleHelper
- Defined in:
- lib/helperful/title_helper.rb
Overview
Title Helper
This module provides an helper for managing page title in Rails views and layouts.
Instance Method Summary collapse
-
#title(*args) ⇒ Object
Title Helper.
Instance Method Details
#title(*args) ⇒ Object
Title Helper
This helper provides both input and output capabilities for managing page title in Rails views and layouts.
When called with args, it stores all args for later retrieval. Additionally, it always return a formatted title so that it can be easily called without arguments to display the full page title.
You can pass some additional options to customize the behavior of the returned string. The following options are supported:
- :separator
-
the separator used to join all title elements, by default a dash.
- :site
-
the name of the site to be appended to page title.
- :headline
-
website headline to be appended to page title, after any element.
Examples
# in a template set the title of the page
<h1><%= title "Latest news" %></h1>
# => <h1>Latest news</h1>
# in the layout print the title of the page
# with the name of the site
<title><%= title :site => 'My Site' %></title>
# => <title>Latest news | My Site</title>
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/helperful/title_helper.rb', line 60 def title(*args) @helperful_title ||= [] ||= { :separator => ' - ', :headline => nil, :site => nil, } = args. @helperful_title += args .merge!() t = @helperful_title.clone t << [:site] t << [:headline] t.compact.join([:separator]) end |