Sha256: d47b3c86594a0d8807a8c4615672784d856c63368d1d542d21cb52a38fb2d799
Contents?: true
Size: 1.2 KB
Versions: 1
Compression:
Stored size: 1.2 KB
Contents
module Title module TitleHelper def title PageTitle.new(controller_path, action_name, controller.view_assigns.symbolize_keys).to_s end class PageTitle def initialize(controller_path, action_name, context) @controller_path = controller_path @action_name = action_name @context = context end def to_s I18n.t( [:titles, controller_name, action_name].join('.'), context.merge(default: defaults) ) end private attr_reader :controller_path, :action_name, :context def application_title :'titles.application' end def guess_title Rails.application.class.to_s.split('::').first end def defaults default_keys_in_lookup_path + [application_title, guess_title] end def controller_name controller_path.gsub('/', '.') end def default_keys_in_lookup_path defaults = [] lookup_path = controller_name.split('.') while lookup_path.length > 0 defaults << ['titles', *lookup_path, 'default'].join('.').to_sym lookup_path.pop end defaults.reverse end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
title-0.0.4 | app/helpers/title/title_helper.rb |