Module: HappyTitles
- Defined in:
- lib/happy-titles.rb,
lib/happy-titles/railtie.rb
Defined Under Namespace
Classes: Railtie
Constant Summary collapse
- @@happy_title_settings =
{ :site => 'My Site', :tagline => 'My short, descriptive and witty tagline', :templates => { :default => [':site | :title', ':title | :site'] } }
Instance Attribute Summary collapse
-
#page_title ⇒ Object
Returns the value of attribute page_title.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#page_title ⇒ Object
Returns the value of attribute page_title.
5 6 7 |
# File 'lib/happy-titles.rb', line 5 def page_title @page_title end |
Class Method Details
.included(base) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/happy-titles.rb', line 35 def self.included(base) base.class_eval do cattr_accessor :happy_title_settings def self.happy_title_template(template_key, format, additional_format = nil) template = [format] template << additional_format if additional_format @@happy_title_settings[:templates][template_key] = template end def self.happy_title_setting(key, value) @@happy_title_settings[key] = value end end end |
Instance Method Details
#happy_title(template_key = :default) ⇒ Object
15 16 17 |
# File 'lib/happy-titles.rb', line 15 def happy_title(template_key = :default) content_tag(:title, render_title_template(template_key)) end |
#title(page_title = nil, settings = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/happy-titles.rb', line 19 def title(page_title = nil, settings = {}) if page_title && page_title.is_a?(Hash) settings = page_title page_title = settings[:title] ? settings[:title] : nil end @happy_title_settings = settings if page_title @page_title = h(page_title.gsub(/<\/?[^>]*>/, '')) if page_title else @page_title || '' end end |