From ae7a4b9678dedbdfae0c62d9cc84667ef7388866 Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Thu, 6 Feb 2014 03:33:33 +0000 Subject: Rails4: add ApplicationHelper#truncate_single_line_raw method replacing truncate_single_line git-svn-id: http://svn.redmine.org/redmine/trunk@12830 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/application_helper.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'app/helpers') diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 54852abf5..e2e3349ed 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -224,7 +224,7 @@ module ApplicationHelper 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) @@ -397,9 +397,17 @@ module ApplicationHelper # 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 @@ -759,7 +767,7 @@ module ApplicationHelper :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 == '#' @@ -841,7 +849,7 @@ module ApplicationHelper 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) -- cgit v1.2.3