Adds a helper for building h2 tags and setting html_title (#14517).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@12048 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
3700378764
commit
2f9050115b
@ -449,12 +449,31 @@ module ApplicationHelper
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns a h2 tag and sets the html title with the given arguments
|
||||||
|
def title(*args)
|
||||||
|
strings = args.map do |arg|
|
||||||
|
if arg.is_a?(Array) && arg.size >= 2
|
||||||
|
link_to(*arg)
|
||||||
|
else
|
||||||
|
h(arg.to_s)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
html_title args.reverse.map {|s| (s.is_a?(Array) ? s.first : s).to_s}
|
||||||
|
content_tag('h2', strings.join(' » ').html_safe)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Sets the html title
|
||||||
|
# Returns the html title when called without arguments
|
||||||
|
# Current project name and app_title and automatically appended
|
||||||
|
# Exemples:
|
||||||
|
# html_title 'Foo', 'Bar'
|
||||||
|
# html_title # => 'Foo - Bar - My Project - Redmine'
|
||||||
def html_title(*args)
|
def html_title(*args)
|
||||||
if args.empty?
|
if args.empty?
|
||||||
title = @html_title || []
|
title = @html_title || []
|
||||||
title << @project.name if @project
|
title << @project.name if @project
|
||||||
title << Setting.app_title unless Setting.app_title == title.last
|
title << Setting.app_title unless Setting.app_title == title.last
|
||||||
title.select {|t| !t.blank? }.join(' - ')
|
title.reject(&:blank?).join(' - ')
|
||||||
else
|
else
|
||||||
@html_title ||= []
|
@html_title ||= []
|
||||||
@html_title += args
|
@html_title += args
|
||||||
|
@ -1231,4 +1231,38 @@ RAW
|
|||||||
s = raw_json(["foo"])
|
s = raw_json(["foo"])
|
||||||
assert s.html_safe?
|
assert s.html_safe?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_html_title_should_app_title_if_not_set
|
||||||
|
assert_equal 'Redmine', html_title
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_html_title_should_join_items
|
||||||
|
html_title 'Foo', 'Bar'
|
||||||
|
assert_equal 'Foo - Bar - Redmine', html_title
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_html_title_should_append_current_project_name
|
||||||
|
@project = Project.find(1)
|
||||||
|
html_title 'Foo', 'Bar'
|
||||||
|
assert_equal 'Foo - Bar - eCookbook - Redmine', html_title
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_title_should_return_a_h2_tag
|
||||||
|
assert_equal '<h2>Foo</h2>', title('Foo')
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_title_should_set_html_title
|
||||||
|
title('Foo')
|
||||||
|
assert_equal 'Foo - Redmine', html_title
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_title_should_turn_arrays_into_links
|
||||||
|
assert_equal '<h2><a href="/foo">Foo</a></h2>', title(['Foo', '/foo'])
|
||||||
|
assert_equal 'Foo - Redmine', html_title
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_title_should_join_items
|
||||||
|
assert_equal '<h2>Foo » Bar</h2>', title('Foo', 'Bar')
|
||||||
|
assert_equal 'Bar - Foo - Redmine', html_title
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user