Class: Titleist::Title
- Inherits:
-
Object
- Object
- Titleist::Title
- Extended by:
- T::Sig
- Defined in:
- lib/titleist/title.rb
Overview
Object that turns passed-in scope details into a String of title text derived from the I18n
locale configuration.
Constant Summary collapse
- FORMAT =
Default title format that can be overridden by changing the i18n key ‘titelist.format`.
'%{page} - %{app}'.freeze
Instance Attribute Summary collapse
-
#page ⇒ String
Override the current page title.
Instance Method Summary collapse
-
#[](key) ⇒ String
Read title context.
-
#[]=(key, value) ⇒ String
Write title context.
-
#app ⇒ String
Global application title.
- #initialize(controller:, action:, **context) ⇒ Titleist::Title constructor
-
#to_s ⇒ String
Format the full page title.
Constructor Details
#initialize(controller:, action:, **context) ⇒ Titleist::Title
17 18 19 20 21 |
# File 'lib/titleist/title.rb', line 17 def initialize(controller:, action:, **context) @controller = controller @action = action @params = context end |
Instance Attribute Details
#page ⇒ String
Override the current page title
53 54 55 56 57 58 |
# File 'lib/titleist/title.rb', line 53 def page @page ||= I18n.t :title, @params.reverse_merge( scope: [*controller_scope, @action], default: default_page_title ) end |
Instance Method Details
#[](key) ⇒ String
Read title context
27 28 29 |
# File 'lib/titleist/title.rb', line 27 def [](key) @params[key] end |
#[]=(key, value) ⇒ String
Write title context
36 37 38 |
# File 'lib/titleist/title.rb', line 36 def []=(key, value) @params[key] = value end |
#app ⇒ String
Global application title.
43 44 45 46 47 48 |
# File 'lib/titleist/title.rb', line 43 def app @app ||= I18n.t :title, @params.reverse_merge( scope: %i[layouts application], default: default_app_title ) end |
#to_s ⇒ String
Format the full page title.
68 69 70 |
# File 'lib/titleist/title.rb', line 68 def to_s I18n.t :format, scope: :titleist, default: FORMAT, app: app, page: page end |