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