Better page_title helper handling for nested blocks
This commit is contained in:
@@ -90,17 +90,18 @@ module Dunlop
|
|||||||
scope_model.human_attribute_name(attribute_name)
|
scope_model.human_attribute_name(attribute_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def page_title(*args)
|
def page_title(*args, &blk)
|
||||||
res = content_tag :h3, class: 'page-title ui header' do
|
extra_content = capture(&blk) if blk.present?
|
||||||
if resource_title?(args)
|
if resource_title?(args)
|
||||||
@scope_model = args[1].is_a?(ActiveRecord::Base) ? args[1].class : args[1]
|
@scope_model = args[1].is_a?(ActiveRecord::Base) ? args[1].class : args[1]
|
||||||
page_title_for_resource(args)
|
content = page_title_for_resource(args)
|
||||||
else
|
else
|
||||||
page_title_for_string(args)
|
content = page_title_for_string(args)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
content_for :page_title, res
|
content += extra_content if extra_content.present?
|
||||||
res
|
title_tag = content_tag(:h3, content, class: 'page-title ui header')
|
||||||
|
content_for :page_title, title_tag
|
||||||
|
title_tag
|
||||||
end
|
end
|
||||||
|
|
||||||
def resource_title?(args)
|
def resource_title?(args)
|
||||||
@@ -109,7 +110,7 @@ module Dunlop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def page_title_for_string(args)
|
def page_title_for_string(args)
|
||||||
title = args.first
|
title = html_escape(args.first)
|
||||||
options = args.last.is_a?(Hash) ? args.last : {}
|
options = args.last.is_a?(Hash) ? args.last : {}
|
||||||
if back_options = options[:back]
|
if back_options = options[:back]
|
||||||
url =
|
url =
|
||||||
@@ -120,7 +121,7 @@ module Dunlop
|
|||||||
end
|
end
|
||||||
if url
|
if url
|
||||||
back_link = link_to content_tag(:i, nil, class: 'left arrow icon'), url, class: 'title-back-link'
|
back_link = link_to content_tag(:i, nil, class: 'left arrow icon'), url, class: 'title-back-link'
|
||||||
title = [back_link, title].join.html_safe
|
title = back_link.safe_concat(title)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
title
|
title
|
||||||
@@ -130,9 +131,9 @@ module Dunlop
|
|||||||
options = args.extract_options!
|
options = args.extract_options!
|
||||||
model = args[1].respond_to?(:model_name) ? args[1] : args[1].class
|
model = args[1].respond_to?(:model_name) ? args[1] : args[1].class
|
||||||
if args.first == :index
|
if args.first == :index
|
||||||
title = t('action.index.label', models: model.model_name.human_plural)
|
title = t('action.index.label', models: model.model_name.human_plural).html_safe
|
||||||
else
|
else
|
||||||
title = t("action.#{args.first}.label", model: model.model_name.human)
|
title = t("action.#{args.first}.label", model: model.model_name.human).html_safe
|
||||||
end
|
end
|
||||||
if back_options = options[:back]
|
if back_options = options[:back]
|
||||||
url =
|
url =
|
||||||
@@ -143,7 +144,7 @@ module Dunlop
|
|||||||
end
|
end
|
||||||
if url
|
if url
|
||||||
back_link = link_to content_tag(:i, nil, class: 'left arrow icon'), url, class: 'title-back-link'
|
back_link = link_to content_tag(:i, nil, class: 'left arrow icon'), url, class: 'title-back-link'
|
||||||
title = [back_link, title].join.html_safe
|
title = back_link.safe_concat(title)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
title
|
title
|
||||||
|
|||||||
Reference in New Issue
Block a user