OSDN Git Service

Fixed: changesets titles should not be multiline in atom feeds (#1356).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 4 Jun 2008 18:13:14 +0000 (18:13 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 4 Jun 2008 18:13:14 +0000 (18:13 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1491 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/application_helper.rb
app/helpers/projects_helper.rb
app/views/common/feed.atom.rxml
app/views/projects/activity.rhtml

index 47a2510..589b054 100644 (file)
@@ -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+)}, '<span class="hours hours-int">\1</span><span class="hours hours-dec">.\2</span>')
   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
index ffbf25e..49a2e57 100644 (file)
@@ -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
index ac087d3..8ceffc9 100644 (file)
@@ -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
index d4b47f7..1a3fd9f 100644 (file)
@@ -7,7 +7,8 @@
 <dl>
 <% @events_by_day[day].sort {|x,y| y.event_datetime <=> x.event_datetime }.each do |e| -%>
   <dt class="<%= e.event_type %>"><span class="time"><%= format_time(e.event_datetime, false) %></span>
-  <%= 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 %></dt>
+  <%= 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 %></dt>
   <dd><span class="description"><%= format_activity_description(e.event_description) %></span>
   <span class="author"><%= e.event_author if e.respond_to?(:event_author) %></span></dd>
 <% end -%>