Add missing "updated" element to entries of project's atom feed
[gitorious:mainline.git] / app / views / projects / show.atom.builder
1 # encoding: utf-8
2 #--
3 #   Copyright (C) 2012 Gitorious AS
4 #   Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
5 #   Copyright (C) 2008 Johan Sørensen <johan@johansorensen.com>
6 #   Copyright (C) 2008 Tor Arne Vestbø <tavestbo@trolltech.com>
7 #
8 #   This program is free software: you can redistribute it and/or modify
9 #   it under the terms of the GNU Affero General Public License as published by
10 #   the Free Software Foundation, either version 3 of the License, or
11 #   (at your option) any later version.
12 #
13 #   This program is distributed in the hope that it will be useful,
14 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 #   GNU Affero General Public License for more details.
17 #
18 #   You should have received a copy of the GNU Affero General Public License
19 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 #++
21
22 namespaced_atom_feed do |feed|
23   feed.title("Gitorious: #{project.slug} activity")
24   feed.updated((events.blank? ? Time.now : events.first.created_at))
25
26   events.map { |event| EventPresenter.build(event, self) }.each do |event|
27     feed.entry(event, :url => Gitorious.url(project_path(project))) do |entry|
28       entry.updated(event.created_at.iso8601)
29       if event.user
30         entry.title("#{h(event.user.login)} #{strip_tags(event.action)}")
31         entry_content = <<-EOS
32   <p>#{link_to event.user.login, user_url(event.user)} #{event.action}</p>
33   <p>#{event.body}<p>
34   EOS
35         if event.has_commits?
36           entry_content << "<ul>"
37           event.events.commits.each do |commit_event|
38             entry_content << %Q{<li>#{h(commit_event.git_actor.name)} }
39             commit_url = project_repository_commit_url(event.target.project, event.target, commit_event.data)
40             entry_content << %Q{#{link_to(h(commit_event.data[0,7]), commit_url)}}
41             entry_content << %Q{: #{truncate(h(commit_event.body), :length => 75)}</li>}
42           end
43           entry_content << "</ul>"
44         end
45         entry.content(entry_content, :type => "html")
46         entry.author do |author|
47           author.name(event.user.login)
48         end
49       else
50         entry.title("#{h(event.actor_display)} #{strip_tags(event.action)}")
51         entry_content = <<-EOS
52           <p>#{event.action}</p>
53           <p>#{event.body}</p>
54         EOS
55         if event.has_commits?
56           entry_content << "<ul>"
57           event.events.commits.each do |commit_event|
58             entry_content << %Q{<li>#{h(commit_event.git_actor.name)} #{h(commit_event.data[0,7])}: #{truncate(h(commit_event.event.body), :length => 75)}</li>}
59           end
60           entry_content << "</ul>"
61         end
62         entry.content(entry_content, :type => "html")
63         entry.author do |author|
64           author.name(event.actor_display)
65         end
66       end
67     end
68   end
69 end