class TitleHelper::PageTitle
Attributes
action_name[R]
application_name[R]
context[R]
controller_path[R]
include_application_name[R]
separator[R]
Public Class Methods
new(controller_path, action_name, context, opts)
click to toggle source
# File lib/pineapples/templates/app/helpers/title_helper.rb, line 16 def initialize(controller_path, action_name, context, opts) @controller_path = controller_path @action_name = action_name @context = context @application_name = opts[:application_name] || humanized_application_name @include_application_name = opts[:include_application_name] || true @separator = opts[:separator] || ' – ' end
Public Instance Methods
to_s()
click to toggle source
# File lib/pineapples/templates/app/helpers/title_helper.rb, line 25 def to_s title = translate_action if include_application_name title << "#{separator}#{application_name}" if title != application_name end title end
Private Instance Methods
application_title_key()
click to toggle source
# File lib/pineapples/templates/app/helpers/title_helper.rb, line 51 def application_title_key :'titles.application' end
controller_i18n_key_lookup_path()
click to toggle source
# File lib/pineapples/templates/app/helpers/title_helper.rb, line 59 def controller_i18n_key_lookup_path controller_path.gsub('/', '.') end
default_keys_in_lookup_path()
click to toggle source
# File lib/pineapples/templates/app/helpers/title_helper.rb, line 67 def default_keys_in_lookup_path defaults = [] lookup_path = controller_i18n_key_lookup_path.split('.') while lookup_path.length > 0 defaults << ['titles', *lookup_path, 'default'].join('.').to_sym lookup_path.pop end defaults.reverse end
defaults()
click to toggle source
# File lib/pineapples/templates/app/helpers/title_helper.rb, line 63 def defaults default_keys_in_lookup_path + [application_title_key, guess_title_key] end
guess_title_key()
click to toggle source
# File lib/pineapples/templates/app/helpers/title_helper.rb, line 55 def guess_title_key Rails.application.class.to_s.split('::').first end
humanized_application_name()
click to toggle source
# File lib/pineapples/templates/app/helpers/title_helper.rb, line 42 def humanized_application_name guess_title_key.underscore.humanize.gsub(/\S+/, &:capitalize) end
translate_action()
click to toggle source
# File lib/pineapples/templates/app/helpers/title_helper.rb, line 46 def translate_action I18n.t("titles.#{controller_i18n_key_lookup_path}.#{action_name}", context.merge(default: defaults)) end
translate_application_name()
click to toggle source
# File lib/pineapples/templates/app/helpers/title_helper.rb, line 37 def translate_application_name return application_name if application_name.present? I18n.t(application_title, default: humanized_application_name) end