class PageTitle::Base
Constants
- ACTION_ALIAS
Set all action aliases.
Attributes
controller[R]
Set the controller instance. It must implement the methods controller_name and action_name.
options[R]
Set the main translation options.
Public Class Methods
new(controller)
click to toggle source
# File lib/page_title.rb, line 26 def initialize(controller) @controller = controller @options = {} end
Public Instance Methods
simple()
click to toggle source
# File lib/page_title.rb, line 35 def simple title_translation end
to_s()
click to toggle source
# File lib/page_title.rb, line 31 def to_s base_translation end
Private Instance Methods
base_translation()
click to toggle source
# File lib/page_title.rb, line 51 def base_translation I18n.t("titles.base", title: title_translation) end
normalized_action_name()
click to toggle source
# File lib/page_title.rb, line 55 def normalized_action_name ACTION_ALIAS.fetch(controller.action_name, controller.action_name) end
normalized_controller_name()
click to toggle source
# File lib/page_title.rb, line 59 def normalized_controller_name controller.class.name.underscore .gsub(/_controller/, "") .gsub(%r[/], ".") end
title_scope()
click to toggle source
# File lib/page_title.rb, line 65 def title_scope [normalized_controller_name, normalized_action_name].join(".") end
title_translation()
click to toggle source
# File lib/page_title.rb, line 40 def title_translation if options[:scope] I18n.t(options[:scope]) else I18n.t( title_scope, options.merge(scope: "titles") ) end end