From 82eedbf6511faf136293fce5ffc394ee0bf3511a Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sun, 28 Aug 2011 17:58:02 +0100 Subject: [PATCH 1/1] Improve formatting of note descriptions in GPX and RSS responses --- app/helpers/application_helper.rb | 16 ++++++++++++++++ app/helpers/browse_helper.rb | 8 -------- app/views/note/_description.html.erb | 8 ++++++++ app/views/note/_note.gpx.builder | 6 ++++-- app/views/note/_note.rss.builder | 4 +++- config/locales/en.yml | 10 +++++----- 6 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 app/views/note/_description.html.erb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 59ba7d171..ec6c455b3 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -133,6 +133,22 @@ module ApplicationHelper content_tag(:span, time_ago_in_words(date), :title => l(date, :format => :friendly)) end + def note_author(object, link_options = {}) + if object.author.nil? + h(object.author_name) + else + link_to h(object.author_name), link_options.merge({:controller => "user", :action => "view", :display_name => object.author_name}) + end + end + + def with_format(format, &block) + old_format = @template_format + @template_format = format + result = block.call + @template_format = old_format + return result + end + private def javascript_strings_for_key(key) diff --git a/app/helpers/browse_helper.rb b/app/helpers/browse_helper.rb index 9a49abd67..a41b39a3d 100644 --- a/app/helpers/browse_helper.rb +++ b/app/helpers/browse_helper.rb @@ -42,14 +42,6 @@ module BrowseHelper end end - def note_author(object) - if object.author.nil? - h(object.author_name) - else - link_to h(object.author_name), :controller => "user", :action => "view", :display_name => object.author_name - end - end - private ICON_TAGS = [ diff --git a/app/views/note/_description.html.erb b/app/views/note/_description.html.erb new file mode 100644 index 000000000..596d63269 --- /dev/null +++ b/app/views/note/_description.html.erb @@ -0,0 +1,8 @@ +
+ <% description.comments.each do |comment| -%> +
+
<%= t "note.description.#{comment.event}_at_by", :when => friendly_date(comment.created_at), :user => note_author(comment, :only_path => false) %>
+
<%= comment.body %>
+
+ <% end -%> +
diff --git a/app/views/note/_note.gpx.builder b/app/views/note/_note.gpx.builder index 91c0cbd98..8b599eb09 100644 --- a/app/views/note/_note.gpx.builder +++ b/app/views/note/_note.gpx.builder @@ -1,6 +1,8 @@ xml.wpt("lon" => note.lon, "lat" => note.lat) do - xml.desc do - xml.cdata! note.flatten_comment("
") + with_format(:html) do + xml.desc do + xml.cdata! render(:partial => "description", :object => note, :format => :html) + end end xml.extension do diff --git a/app/views/note/_note.rss.builder b/app/views/note/_note.rss.builder index 856b4cc62..49f0a5171 100644 --- a/app/views/note/_note.rss.builder +++ b/app/views/note/_note.rss.builder @@ -9,7 +9,9 @@ xml.item do xml.link url_for(:controller => "browse", :action => "note", :id => note.id, :only_path => false) xml.guid url_for(:controller => "note", :action => "read", :id => note.id, :only_path => false) - xml.description htmlize(note.flatten_comment("

")) + with_format(:html) do + xml.description render(:partial => "description", :object => note) + end xml.author note.author_name xml.pubDate note.updated_at.to_s(:rfc822) xml.geo :lat, note.lat diff --git a/config/locales/en.yml b/config/locales/en.yml index 2f558eb4d..63b15233f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -293,10 +293,6 @@ en: at_by: "%{when} ago by %{user}" description: "Description:" comments: "Comments:" - - comment_by: "Comment by: " - comment: "Comment:" - date: "Date:" changeset: changeset_paging_nav: showing_page: "Showing page %{page}" @@ -1926,6 +1922,11 @@ en: revoker: "Revoker:" needs_view: "The user needs to log in before this block will be cleared." note: + description: + opened_at_by: "Created %{when} ago by %{user}" + commented_at_by: "Updated %{when} ago by %{user}" + closed_at_by: "Resolved %{when} ago by %{user}" + reopened_at_by: "Reactivated %{when} ago by %{user}" rss: title: "OpenStreetMap Notes" description_area: "A list of notes, reported, commented on or closed in your area [(%{min_lat}|%{min_lon}) -- (%{max_lat}|%{max_lon})]" @@ -1939,7 +1940,6 @@ en: description: "Notes submitted or commented on by %{user}" id: "Id" last_changed: "Last changed" - javascripts: map: base: -- 2.43.2