From 4db45b8ceddfa77e1935b7a4f1939b33d11244aa Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Wed, 4 Jun 2008 18:13:14 +0000 Subject: [PATCH] Fixed: changesets titles should not be multiline in atom feeds (#1356). git-svn-id: http://redmine.rubyforge.org/svn/trunk@1491 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/application_helper.rb | 11 +++++++++-- app/helpers/projects_helper.rb | 4 ++++ app/views/common/feed.atom.rxml | 4 ++-- app/views/projects/activity.rhtml | 3 ++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 47a25105..589b054f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -90,6 +90,11 @@ module ApplicationHelper include_date ? local.strftime("#{@date_format} #{@time_format}") : local.strftime(@time_format) end + # Truncates and returns the string as a single line + def truncate_single_line(string, *args) + truncate(string, *args).gsub(%r{[\r\n]+}m, ' ') + end + def html_hours(text) text.gsub(%r{(\d+)\.(\d+)}, '\1.\2') end @@ -301,7 +306,7 @@ module ApplicationHelper if project && (changeset = project.changesets.find_by_revision(oid)) link = link_to("r#{oid}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => oid}, :class => 'changeset', - :title => truncate(changeset.comments, 100)) + :title => truncate_single_line(changeset.comments, 100)) end elsif sep == '#' oid = oid.to_i @@ -340,7 +345,9 @@ module ApplicationHelper end when 'commit' if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"])) - link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision}, :class => 'changeset', :title => truncate(changeset.comments, 100) + link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision}, + :class => 'changeset', + :title => truncate_single_line(changeset.comments, 100) end when 'source', 'export' if project && project.repository diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index ffbf25e8..49a2e572 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -21,6 +21,10 @@ module ProjectsHelper link_to h(version.name), { :controller => 'versions', :action => 'show', :id => version }, options end + def format_activity_title(text) + h(truncate_single_line(text, 100)) + end + def format_activity_day(date) date == Date.today ? l(:label_today).titleize : format_date(date) end diff --git a/app/views/common/feed.atom.rxml b/app/views/common/feed.atom.rxml index ac087d36..8ceffc91 100644 --- a/app/views/common/feed.atom.rxml +++ b/app/views/common/feed.atom.rxml @@ -1,6 +1,6 @@ xml.instruct! xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do - xml.title @title + xml.title truncate_single_line(@title, 100) xml.link "rel" => "self", "href" => url_for(params.merge({:format => nil, :only_path => false})) xml.link "rel" => "alternate", "href" => url_for(:controller => 'welcome', :only_path => false) xml.id url_for(:controller => 'welcome', :only_path => false) @@ -10,7 +10,7 @@ xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do @items.each do |item| xml.entry do url = url_for(item.event_url(:only_path => false)) - xml.title truncate(item.event_title, 100) + xml.title truncate_single_line(item.event_title, 100) xml.link "rel" => "alternate", "href" => url xml.id url xml.updated item.event_datetime.xmlschema diff --git a/app/views/projects/activity.rhtml b/app/views/projects/activity.rhtml index d4b47f7b..1a3fd9ff 100644 --- a/app/views/projects/activity.rhtml +++ b/app/views/projects/activity.rhtml @@ -7,7 +7,8 @@
<% @events_by_day[day].sort {|x,y| y.event_datetime <=> x.event_datetime }.each do |e| -%>
<%= format_time(e.event_datetime, false) %> - <%= content_tag('span', h(e.project), :class => 'project') if @project.nil? || @project != e.project %> <%= link_to h(truncate(e.event_title, 100)), e.event_url %>
+ <%= content_tag('span', h(e.project), :class => 'project') if @project.nil? || @project != e.project %> + <%= link_to format_activity_title(e.event_title), e.event_url %>
<%= format_activity_description(e.event_description) %> <%= e.event_author if e.respond_to?(:event_author) %>
<% end -%> -- 2.11.0