From 560e41ebf990e8d46d3b3df97b52d5e74083668c Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sat, 7 May 2011 14:44:48 +0100 Subject: [PATCH] Factor out common code into partials --- app/views/map_bugs/_bug.rss.builder | 22 +++++++++++++++++++ app/views/map_bugs/_bug.xml.builder | 27 ++++++++++++++++++++++++ app/views/map_bugs/get_bugs.rss.builder | 23 +------------------- app/views/map_bugs/get_bugs.xml.builder | 28 +------------------------ app/views/map_bugs/read.rss.builder | 23 ++------------------ app/views/map_bugs/read.xml.builder | 24 +-------------------- 6 files changed, 54 insertions(+), 93 deletions(-) create mode 100644 app/views/map_bugs/_bug.rss.builder create mode 100644 app/views/map_bugs/_bug.xml.builder diff --git a/app/views/map_bugs/_bug.rss.builder b/app/views/map_bugs/_bug.rss.builder new file mode 100644 index 000000000..59367da67 --- /dev/null +++ b/app/views/map_bugs/_bug.rss.builder @@ -0,0 +1,22 @@ +xml.item do + if bug.status == "closed" + xml.title t('bugs.rss.closed', :place => bug.nearby_place) + elsif bug.map_bug_comment.length > 1 + xml.title t('bugs.rss.comment', :place => bug.nearby_place) + else + xml.title t('bugs.rss.new', :place => bug.nearby_place) + end + + xml.link url_for(:controller => "browse", :action => "bug", :id => bug.id, :only_path => false) + xml.guid url_for(:controller => "map_bugs", :action => "read", :id => bug.id, :only_path => false) + xml.description htmlize(bug.flatten_comment("

")) + + unless bug.map_bug_comment.empty? + xml.author bug.map_bug_comment[-1].commenter_name + end + + xml.pubDate bug.last_changed.to_s(:rfc822) + xml.geo :lat, bug.lat + xml.geo :long, bug.lon + xml.georss :point, "#{bug.lat} #{bug.lon}" +end diff --git a/app/views/map_bugs/_bug.xml.builder b/app/views/map_bugs/_bug.xml.builder new file mode 100644 index 000000000..69683b7dd --- /dev/null +++ b/app/views/map_bugs/_bug.xml.builder @@ -0,0 +1,27 @@ +xml.bug("lon" => bug.lon, "lat" => bug.lat) do + xml.id bug.id + xml.date_created bug.date_created + xml.nearby bug.nearby_place + xml.status bug.status + + if bug.status == "closed" + xml.date_closed bug.date_closed + end + + xml.comments do + bug.map_bug_comment.each do |comment| + xml.comment do + xml.date comment.date_created + + unless comment.commenter_id.nil? + xml.uid comment.commenter_id + xml.user comment.user.display_name + else + xml.user comment.commenter_name + end + + xml.text comment.comment + end + end + end +end diff --git a/app/views/map_bugs/get_bugs.rss.builder b/app/views/map_bugs/get_bugs.rss.builder index a8ae98dc8..a1852fab1 100644 --- a/app/views/map_bugs/get_bugs.rss.builder +++ b/app/views/map_bugs/get_bugs.rss.builder @@ -8,27 +8,6 @@ xml.rss("version" => "2.0", xml.description t('bugs.rss.description_area', :min_lat => @min_lat, :min_lon => @min_lon, :max_lat => @max_lat, :max_lon => @max_lon ) xml.link url_for(:controller => "site", :action => "index", :only_path => false) - for bug in @bugs - xml.item do - if bug.status == "closed" - xml.title t('bugs.rss.closed', :place => bug.nearby_place) - else if bug.map_bug_comment.length > 1 - xml.title t('bugs.rss.comment', :place => bug.nearby_place) - else - xml.title t('bugs.rss.new', :place => bug.nearby_place) - end end - - xml.link url_for(:controller => "browse", :action => "bug", :id => bug.id, :only_path => false) - xml.guid url_for(:controller => "browse", :action => "bug", :id => bug.id, :only_path => false) - xml.description htmlize(bug.flatten_comment("

")) - if (!bug.map_bug_comment.empty?) - xml.author bug.map_bug_comment[-1].commenter_name - end - xml.pubDate bug.last_changed.to_s(:rfc822) - xml.geo :lat, bug.lat - xml.geo :long, bug.lon - xml.georss :point, "#{bug.lat} #{bug.lon}" - end - end + xml << render(:partial => "bug", :collection => @bugs) end end diff --git a/app/views/map_bugs/get_bugs.xml.builder b/app/views/map_bugs/get_bugs.xml.builder index a594506cd..16be0598b 100644 --- a/app/views/map_bugs/get_bugs.xml.builder +++ b/app/views/map_bugs/get_bugs.xml.builder @@ -1,29 +1,3 @@ xml.instruct! -xml.bugs do - for bug in @bugs - xml.bug("lon" => bug.lon, "lat" => bug.lat) do - xml.id bug.id - xml.date_created bug.date_created - xml.nearby bug.nearby_place - xml.status bug.status - if bug.status == "closed" - xml.date_closed bug.date_closed - end - xml.comments do - for comment in bug.map_bug_comment - xml.comment do - xml.date comment.date_created - if !comment.commenter_id.nil? - xml.uid comment.commenter_id - xml.user comment.user.display_name - else - xml.user comment.commenter_name - end - xml.text comment.comment - end - end - end - end - end -end +xml << render(:partial => "bug", :collection => @bugs) diff --git a/app/views/map_bugs/read.rss.builder b/app/views/map_bugs/read.rss.builder index 501ed6bf8..aba1f831d 100644 --- a/app/views/map_bugs/read.rss.builder +++ b/app/views/map_bugs/read.rss.builder @@ -5,28 +5,9 @@ xml.rss("version" => "2.0", "xmlns:georss" => "http://www.georss.org/georss") do xml.channel do xml.title "OpenStreetBugs" - xml.description t('bugs.rss.description_item',:id => @bug.id) + xml.description t('bugs.rss.description_item', :id => @bug.id) xml.link url_for(:controller => "site", :action => "index", :only_path => false) - xml.item do - if @bug.status == "closed" - xml.title t('bugs.rss.closed', :place => @bug.nearby_place) - else if @bug.map_bug_comment.length > 1 - xml.title t('bugs.rss.comment', :place => @bug.nearby_place) - else - xml.title t('bugs.rss.new', :place => @bug.nearby_place) - end end - - xml.link url_for(:controller => "browse", :action => "bug", :id => @bug.id, :only_path => false) - xml.guid url_for(:controller => "map_bugs", :action => "read", :id => @bug.id, :only_path => false) - xml.description htmlize(@bug.flatten_comment("

")) - if (!@bug.map_bug_comment.empty?) - xml.author @bug.map_bug_comment[-1].commenter_name - end - xml.pubDate @bug.last_changed.to_s(:rfc822) - xml.geo :lat, @bug.lat - xml.geo :long, @bug.lon - xml.georss :point, "#{@bug.lat} #{@bug.lon}" - end + xml << render(:partial => "bug", :object => @bug) end end diff --git a/app/views/map_bugs/read.xml.builder b/app/views/map_bugs/read.xml.builder index f9d7ddaa1..82fe04c4b 100644 --- a/app/views/map_bugs/read.xml.builder +++ b/app/views/map_bugs/read.xml.builder @@ -1,25 +1,3 @@ xml.instruct! -xml.bug("lon" => @bug.lon, "lat" => @bug.lat) do - xml.id @bug.id - xml.date_created @bug.date_created - xml.nearby @bug.nearby_place - xml.status @bug.status - if @bug.status == "closed" - xml.date_closed @bug.date_closed - end - xml.comments do - for comment in @bug.map_bug_comment - xml.comment do - xml.date comment.date_created - if !comment.commenter_id.nil? - xml.uid comment.commenter_id - xml.user comment.user.display_name - else - xml.user comment.commenter_name - end - xml.text comment.comment - end - end - end -end +xml << render(:partial => "bug", :object => @bug) -- 2.39.5