@@ -449,12 +449,31 module ApplicationHelper | |||||
449 | end |
|
449 | end | |
450 | end |
|
450 | end | |
451 |
|
451 | |||
|
452 | # Returns a h2 tag and sets the html title with the given arguments | |||
|
453 | def title(*args) | |||
|
454 | strings = args.map do |arg| | |||
|
455 | if arg.is_a?(Array) && arg.size >= 2 | |||
|
456 | link_to(*arg) | |||
|
457 | else | |||
|
458 | h(arg.to_s) | |||
|
459 | end | |||
|
460 | end | |||
|
461 | html_title args.reverse.map {|s| (s.is_a?(Array) ? s.first : s).to_s} | |||
|
462 | content_tag('h2', strings.join(' » ').html_safe) | |||
|
463 | end | |||
|
464 | ||||
|
465 | # Sets the html title | |||
|
466 | # Returns the html title when called without arguments | |||
|
467 | # Current project name and app_title and automatically appended | |||
|
468 | # Exemples: | |||
|
469 | # html_title 'Foo', 'Bar' | |||
|
470 | # html_title # => 'Foo - Bar - My Project - Redmine' | |||
452 | def html_title(*args) |
|
471 | def html_title(*args) | |
453 | if args.empty? |
|
472 | if args.empty? | |
454 | title = @html_title || [] |
|
473 | title = @html_title || [] | |
455 | title << @project.name if @project |
|
474 | title << @project.name if @project | |
456 | title << Setting.app_title unless Setting.app_title == title.last |
|
475 | title << Setting.app_title unless Setting.app_title == title.last | |
457 |
title. |
|
476 | title.reject(&:blank?).join(' - ') | |
458 | else |
|
477 | else | |
459 | @html_title ||= [] |
|
478 | @html_title ||= [] | |
460 | @html_title += args |
|
479 | @html_title += args |
@@ -1231,4 +1231,38 RAW | |||||
1231 | s = raw_json(["foo"]) |
|
1231 | s = raw_json(["foo"]) | |
1232 | assert s.html_safe? |
|
1232 | assert s.html_safe? | |
1233 | end |
|
1233 | end | |
|
1234 | ||||
|
1235 | def test_html_title_should_app_title_if_not_set | |||
|
1236 | assert_equal 'Redmine', html_title | |||
|
1237 | end | |||
|
1238 | ||||
|
1239 | def test_html_title_should_join_items | |||
|
1240 | html_title 'Foo', 'Bar' | |||
|
1241 | assert_equal 'Foo - Bar - Redmine', html_title | |||
|
1242 | end | |||
|
1243 | ||||
|
1244 | def test_html_title_should_append_current_project_name | |||
|
1245 | @project = Project.find(1) | |||
|
1246 | html_title 'Foo', 'Bar' | |||
|
1247 | assert_equal 'Foo - Bar - eCookbook - Redmine', html_title | |||
|
1248 | end | |||
|
1249 | ||||
|
1250 | def test_title_should_return_a_h2_tag | |||
|
1251 | assert_equal '<h2>Foo</h2>', title('Foo') | |||
|
1252 | end | |||
|
1253 | ||||
|
1254 | def test_title_should_set_html_title | |||
|
1255 | title('Foo') | |||
|
1256 | assert_equal 'Foo - Redmine', html_title | |||
|
1257 | end | |||
|
1258 | ||||
|
1259 | def test_title_should_turn_arrays_into_links | |||
|
1260 | assert_equal '<h2><a href="/foo">Foo</a></h2>', title(['Foo', '/foo']) | |||
|
1261 | assert_equal 'Foo - Redmine', html_title | |||
|
1262 | end | |||
|
1263 | ||||
|
1264 | def test_title_should_join_items | |||
|
1265 | assert_equal '<h2>Foo » Bar</h2>', title('Foo', 'Bar') | |||
|
1266 | assert_equal 'Bar - Foo - Redmine', html_title | |||
|
1267 | end | |||
1234 | end |
|
1268 | end |
General Comments 0
You need to be logged in to leave comments.
Login now