@@ -224,7 +224,7 module ApplicationHelper | |||||
224 | end |
|
224 | end | |
225 |
|
225 | |||
226 | def format_activity_title(text) |
|
226 | def format_activity_title(text) | |
227 |
h(truncate_single_line(text, |
|
227 | h(truncate_single_line_raw(text, 100)) | |
228 | end |
|
228 | end | |
229 |
|
229 | |||
230 | def format_activity_day(date) |
|
230 | def format_activity_day(date) | |
@@ -397,9 +397,17 module ApplicationHelper | |||||
397 |
|
397 | |||
398 | # Truncates and returns the string as a single line |
|
398 | # Truncates and returns the string as a single line | |
399 | def truncate_single_line(string, *args) |
|
399 | def truncate_single_line(string, *args) | |
|
400 | ActiveSupport::Deprecation.warn( | |||
|
401 | "ApplicationHelper#truncate_single_line is deprecated and will be removed in Rails 4 poring") | |||
|
402 | # Rails 4 ActionView::Helpers::TextHelper#truncate escapes. | |||
|
403 | # So, result is broken. | |||
400 | truncate(string.to_s, *args).gsub(%r{[\r\n]+}m, ' ') |
|
404 | truncate(string.to_s, *args).gsub(%r{[\r\n]+}m, ' ') | |
401 | end |
|
405 | end | |
402 |
|
406 | |||
|
407 | def truncate_single_line_raw(string, length) | |||
|
408 | string.truncate(length).gsub(%r{[\r\n]+}m, ' ') | |||
|
409 | end | |||
|
410 | ||||
403 | # Truncates at line break after 250 characters or options[:length] |
|
411 | # Truncates at line break after 250 characters or options[:length] | |
404 | def truncate_lines(string, options={}) |
|
412 | def truncate_lines(string, options={}) | |
405 | length = options[:length] || 250 |
|
413 | length = options[:length] || 250 | |
@@ -759,7 +767,7 module ApplicationHelper | |||||
759 | :repository_id => repository.identifier_param, |
|
767 | :repository_id => repository.identifier_param, | |
760 | :rev => changeset.revision}, |
|
768 | :rev => changeset.revision}, | |
761 | :class => 'changeset', |
|
769 | :class => 'changeset', | |
762 |
:title => truncate_single_line(changeset.comments, |
|
770 | :title => truncate_single_line_raw(changeset.comments, 100)) | |
763 | end |
|
771 | end | |
764 | end |
|
772 | end | |
765 | elsif sep == '#' |
|
773 | elsif sep == '#' | |
@@ -841,7 +849,7 module ApplicationHelper | |||||
841 | if repository && (changeset = Changeset.visible.where("repository_id = ? AND scmid LIKE ?", repository.id, "#{name}%").first) |
|
849 | if repository && (changeset = Changeset.visible.where("repository_id = ? AND scmid LIKE ?", repository.id, "#{name}%").first) | |
842 | link = link_to h("#{project_prefix}#{repo_prefix}#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :repository_id => repository.identifier_param, :rev => changeset.identifier}, |
|
850 | link = link_to h("#{project_prefix}#{repo_prefix}#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :repository_id => repository.identifier_param, :rev => changeset.identifier}, | |
843 | :class => 'changeset', |
|
851 | :class => 'changeset', | |
844 |
:title => truncate_single_line(changeset.comments, |
|
852 | :title => truncate_single_line_raw(changeset.comments, 100) | |
845 | end |
|
853 | end | |
846 | else |
|
854 | else | |
847 | if repository && User.current.allowed_to?(:browse_repository, project) |
|
855 | if repository && User.current.allowed_to?(:browse_repository, project) |
@@ -1,6 +1,6 | |||||
1 | xml.instruct! |
|
1 | xml.instruct! | |
2 | xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do |
|
2 | xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do | |
3 |
xml.title truncate_single_line(@title, |
|
3 | xml.title truncate_single_line_raw(@title, 100) | |
4 | xml.link "rel" => "self", "href" => url_for(params.merge(:only_path => false)) |
|
4 | xml.link "rel" => "self", "href" => url_for(params.merge(:only_path => false)) | |
5 | xml.link "rel" => "alternate", "href" => url_for(params.merge(:only_path => false, :format => nil, :key => nil)) |
|
5 | xml.link "rel" => "alternate", "href" => url_for(params.merge(:only_path => false, :format => nil, :key => nil)) | |
6 | xml.id url_for(:controller => 'welcome', :only_path => false) |
|
6 | xml.id url_for(:controller => 'welcome', :only_path => false) | |
@@ -12,9 +12,9 xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do | |||||
12 | xml.entry do |
|
12 | xml.entry do | |
13 | url = url_for(item.event_url(:only_path => false)) |
|
13 | url = url_for(item.event_url(:only_path => false)) | |
14 | if @project |
|
14 | if @project | |
15 |
xml.title truncate_single_line(item.event_title, |
|
15 | xml.title truncate_single_line_raw(item.event_title, 100) | |
16 | else |
|
16 | else | |
17 |
xml.title truncate_single_line("#{item.project} - #{item.event_title}", |
|
17 | xml.title truncate_single_line_raw("#{item.project} - #{item.event_title}", 100) | |
18 | end |
|
18 | end | |
19 | xml.link "rel" => "alternate", "href" => url |
|
19 | xml.link "rel" => "alternate", "href" => url | |
20 | xml.id url |
|
20 | xml.id url |
@@ -1388,10 +1388,10 RAW | |||||
1388 |
|
1388 | |||
1389 | def test_truncate_single_line |
|
1389 | def test_truncate_single_line | |
1390 | str = "01234" |
|
1390 | str = "01234" | |
1391 |
result = truncate_single_line("#{str}\n#{str}", |
|
1391 | result = truncate_single_line_raw("#{str}\n#{str}", 10) | |
1392 | assert_equal "01234 0...", result |
|
1392 | assert_equal "01234 0...", result | |
1393 | assert !result.html_safe? |
|
1393 | assert !result.html_safe? | |
1394 |
result = truncate_single_line("#{str}<&#>\n#{str}#{str}", |
|
1394 | result = truncate_single_line_raw("#{str}<&#>\n#{str}#{str}", 16) | |
1395 | assert_equal "01234<&#> 012...", result |
|
1395 | assert_equal "01234<&#> 012...", result | |
1396 | assert !result.html_safe? |
|
1396 | assert !result.html_safe? | |
1397 | end |
|
1397 | end | |
@@ -1399,7 +1399,7 RAW | |||||
1399 | def test_truncate_single_line_non_ascii |
|
1399 | def test_truncate_single_line_non_ascii | |
1400 | ja = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e" |
|
1400 | ja = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e" | |
1401 | ja.force_encoding('UTF-8') if ja.respond_to?(:force_encoding) |
|
1401 | ja.force_encoding('UTF-8') if ja.respond_to?(:force_encoding) | |
1402 |
result = truncate_single_line("#{ja}\n#{ja}\n#{ja}", |
|
1402 | result = truncate_single_line_raw("#{ja}\n#{ja}\n#{ja}", 10) | |
1403 | assert_equal "#{ja} #{ja}...", result |
|
1403 | assert_equal "#{ja} #{ja}...", result | |
1404 | assert !result.html_safe? |
|
1404 | assert !result.html_safe? | |
1405 | end |
|
1405 | end |
General Comments 0
You need to be logged in to leave comments.
Login now