app/helpers/page_title_helper.rb in stationed-0.3.0 vs app/helpers/page_title_helper.rb in stationed-0.4.0
- old
+ new
@@ -21,18 +21,20 @@
# @example Set the page title to a string
# page_title 'Welcome'
# @example Set the page title based on a model name
# page_title Post.find(1)
# # example translation key: 'Editing %{singular} %{id}'
+ # @example Pass along extra arguments to interpolate
+ # page_title @post, author: @post.author.name
# @example Show the page title
# <title><%= title %></title>
#
# @param [String, #model_name] String or ActiveModel-compliant object
# @return [String] page title component or formatted page title
- def page_title(new_title = nil)
+ def page_title(new_title = nil, options = {})
if new_title
- title_from_string_or_record_or_class(new_title).tap do |str|
+ title_from_string_or_record_or_class(new_title, options).tap do |str|
content_for :page_title, str
end
elsif content_for? :page_title
formatted_title
else
@@ -41,18 +43,18 @@
end
private
def standard_title
- I18n.translate(
+ translate(
standard_defaults.first,
default: standard_defaults.drop(1)
)
end
def formatted_title
- I18n.translate(
+ translate(
formatted_defaults.first,
title: content_for(:page_title),
default: formatted_defaults.drop(1)
)
end
@@ -61,18 +63,18 @@
options.reverse_merge!(
default: model_defaults.drop(1),
singular: klass.model_name.human,
plural: klass.model_name.human.pluralize
)
- I18n.translate model_defaults.first, options
+ translate model_defaults.first, options
end
- def title_from_string_or_record_or_class(object)
+ def title_from_string_or_record_or_class(object, options)
if object.respond_to?(:model_name)
- title_for_class(object)
+ title_for_class(object, options)
elsif object.class.respond_to?(:model_name)
- title_for_class(object.class, id: object.to_param)
+ title_for_class(object.class, options.reverse_merge(id: object.to_param))
else
object
end
end
@@ -97,9 +99,10 @@
def model_defaults
[
:"page_title.#{controller_name}.#{action_name}.model",
:"page_title.#{controller_name}.model",
+ :"page_title.default.#{action_name}.model",
:'page_title.default.model',
:'page_title.default.standard',
::Rails.application.class.parent_name
]
end