end
def format_activity_title(text)
- h(truncate_single_line(text, :length => 100))
+ h(truncate_single_line_raw(text, 100))
end
def format_activity_day(date)
# Truncates and returns the string as a single line
def truncate_single_line(string, *args)
+ ActiveSupport::Deprecation.warn(
+ "ApplicationHelper#truncate_single_line is deprecated and will be removed in Rails 4 poring")
+ # Rails 4 ActionView::Helpers::TextHelper#truncate escapes.
+ # So, result is broken.
truncate(string.to_s, *args).gsub(%r{[\r\n]+}m, ' ')
end
+ def truncate_single_line_raw(string, length)
+ string.truncate(length).gsub(%r{[\r\n]+}m, ' ')
+ end
+
# Truncates at line break after 250 characters or options[:length]
def truncate_lines(string, options={})
length = options[:length] || 250
:repository_id => repository.identifier_param,
:rev => changeset.revision},
:class => 'changeset',
- :title => truncate_single_line(changeset.comments, :length => 100))
+ :title => truncate_single_line_raw(changeset.comments, 100))
end
end
elsif sep == '#'
if repository && (changeset = Changeset.visible.where("repository_id = ? AND scmid LIKE ?", repository.id, "#{name}%").first)
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},
:class => 'changeset',
- :title => truncate_single_line(changeset.comments, :length => 100)
+ :title => truncate_single_line_raw(changeset.comments, 100)
end
else
if repository && User.current.allowed_to?(:browse_repository, project)
xml.instruct!
xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
- xml.title truncate_single_line(@title, :length => 100)
+ xml.title truncate_single_line_raw(@title, 100)
xml.link "rel" => "self", "href" => url_for(params.merge(:only_path => false))
xml.link "rel" => "alternate", "href" => url_for(params.merge(:only_path => false, :format => nil, :key => nil))
xml.id url_for(:controller => 'welcome', :only_path => false)
xml.entry do
url = url_for(item.event_url(:only_path => false))
if @project
- xml.title truncate_single_line(item.event_title, :length => 100)
+ xml.title truncate_single_line_raw(item.event_title, 100)
else
- xml.title truncate_single_line("#{item.project} - #{item.event_title}", :length => 100)
+ xml.title truncate_single_line_raw("#{item.project} - #{item.event_title}", 100)
end
xml.link "rel" => "alternate", "href" => url
xml.id url
def test_truncate_single_line
str = "01234"
- result = truncate_single_line("#{str}\n#{str}", :length => 10)
+ result = truncate_single_line_raw("#{str}\n#{str}", 10)
assert_equal "01234 0...", result
assert !result.html_safe?
- result = truncate_single_line("#{str}<&#>\n#{str}#{str}", :length => 16)
+ result = truncate_single_line_raw("#{str}<&#>\n#{str}#{str}", 16)
assert_equal "01234<&#> 012...", result
assert !result.html_safe?
end
def test_truncate_single_line_non_ascii
ja = "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
ja.force_encoding('UTF-8') if ja.respond_to?(:force_encoding)
- result = truncate_single_line("#{ja}\n#{ja}\n#{ja}", :length => 10)
+ result = truncate_single_line_raw("#{ja}\n#{ja}\n#{ja}", 10)
assert_equal "#{ja} #{ja}...", result
assert !result.html_safe?
end