Module: PageTitleHelper
- Defined in:
- lib/page_title_helper.rb,
lib/page_title_helper/version.rb
Overview
PageTitleHelper
Defined Under Namespace
Modules: Interpolations
Constant Summary collapse
- VERSION =
'4.0.0'
Class Method Summary collapse
-
.formats ⇒ Object
Defined alias formats, pretty useful.
-
.interpolates(key, &block) ⇒ Object
Add new, custom, interpolation.
-
.options ⇒ Object
Default options, which are globally referenced and can be changed globally, which might be useful in some cases.
Instance Method Summary collapse
- #page_title(options = nil) ⇒ Object
-
#page_title!(*args) ⇒ Object
Specify page title.
Class Method Details
.formats ⇒ Object
Defined alias formats, pretty useful.
51 52 53 54 55 56 57 |
# File 'lib/page_title_helper.rb', line 51 def self.formats @formats ||= { app: ':app', default: ':title - :app', title: ':title' } end |
.interpolates(key, &block) ⇒ Object
Add new, custom, interpolation.
37 38 39 |
# File 'lib/page_title_helper.rb', line 37 def self.interpolates(key, &block) Interpolations.send(:define_method, key, &block) end |
.options ⇒ Object
Default options, which are globally referenced and can be changed globally, which might be useful in some cases.
43 44 45 46 47 48 |
# File 'lib/page_title_helper.rb', line 43 def self. @options ||= { format: :default, default: :'app.tagline' } end |
Instance Method Details
#page_title(options = nil) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/page_title_helper.rb', line 65 def page_title( = nil) return page_title!(yield) if block_given? # define title = PageTitleHelper..merge( || {}).symbolize_keys! [:format] ||= :title # handles :format => false .assert_valid_keys(:app, :default, :format) # read page title and split into 'real' title and customized format title = @_page_title ||= page_title_from_translation([:default]) title, [:format] = *(title << [:format]) if title.is_a?(Array) # handle format aliases format = .delete(:format) format = PageTitleHelper.formats[format] if PageTitleHelper.formats.include?(format) # construct basic env to pass around env = { title: title, app: .delete(:app), options: , view: self } # interpolate format Interpolations.interpolate(format, env) end |
#page_title!(*args) ⇒ Object
Specify page title
60 61 62 63 |
# File 'lib/page_title_helper.rb', line 60 def page_title!(*args) @_page_title = args.size > 1 ? args : args.first @_page_title.is_a?(Array) ? @_page_title.first : @_page_title end |