From: Tom Hughes Date: Fri, 6 Jan 2012 00:24:51 +0000 (+0000) Subject: Use jsonify to create JSON for notes so that it is properly formatted X-Git-Tag: live~5616^2~123 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/732c20bf1b2709490c200696bed44d57346a2ffb Use jsonify to create JSON for notes so that it is properly formatted --- diff --git a/Gemfile b/Gemfile index 08dafa0cc..0f867f3d5 100644 --- a/Gemfile +++ b/Gemfile @@ -18,6 +18,7 @@ gem 'oauth-plugin', '>= 0.4.0.pre7' gem 'open_id_authentication', '>= 1.1.0' gem 'validates_email_format_of', '>= 1.5.1' gem 'composite_primary_keys', '>= 4.1.1' +gem 'jsonify-rails' # Load libxml support for XML parsing and generation gem 'libxml-ruby', '>= 2.0.5', :require => 'libxml' diff --git a/Gemfile.lock b/Gemfile.lock index 3343161f9..482d9c3ed 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -57,6 +57,10 @@ GEM railties (~> 3.0) thor (~> 0.14) json (1.6.1) + jsonify (0.2.0) + jsonify-rails (0.2.0) + actionpack + jsonify (>= 0.2.0) libv8 (3.3.10.4) libxml-ruby (2.2.2) mail (2.3.0) @@ -155,6 +159,7 @@ DEPENDENCIES dynamic_form httpclient jquery-rails + jsonify-rails libxml-ruby (>= 2.0.5) memcache-client memcached diff --git a/app/views/note/_note.json.erb b/app/views/note/_note.json.erb deleted file mode 100644 index 0d101f021..000000000 --- a/app/views/note/_note.json.erb +++ /dev/null @@ -1,19 +0,0 @@ -{ - "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [ <%= note.lon %>, <%= note.lat %> ] - }, - "properties": { - "id": <%= note.id %>, - "date_created": "<%= note.created_at %>", - "nearby": "<%= note.nearby_place %>", - "status": "<%= note.status %>", -<% if note.status == "closed" -%> - "closed_at": "<%= note.closed_at %>", -<% end -%> - "comments": [ - <%= render :partial => "note_comment", :collection => note.comments, :spacer_template => "note_spacer" -%> - ] - } -} diff --git a/app/views/note/_note.json.jsonify b/app/views/note/_note.json.jsonify new file mode 100644 index 000000000..a6ef9792e --- /dev/null +++ b/app/views/note/_note.json.jsonify @@ -0,0 +1,21 @@ +json.type "Feature" + +json.geometry do + json.type "Point" + json.coordinates [ note.lon, note.lat ] +end + +json.properties do + json.id note.id + json.date_created note.created_at + json.nearby note.nearby_place + json.status note.status + json.closed_at note.closed_at if note.status == "closed" + + json.comments(note.comments) do |comment| + json.date comment.created_at + json.uid comment.author_id unless comment.author_id.nil? + json.user comment.author_name + json.text comment.body + end +end diff --git a/app/views/note/_note_comment.json.erb b/app/views/note/_note_comment.json.erb deleted file mode 100644 index 405a87dcb..000000000 --- a/app/views/note/_note_comment.json.erb +++ /dev/null @@ -1,8 +0,0 @@ -{ - "date": "<%= note_comment.created_at %>", -<% unless note_comment.author_id.nil? -%> - "uid": <%= note_comment.author_id %>, -<% end -%> - "user": "<%= note_comment.author_name %>", - "text": "<%= note_comment.body %>" -} diff --git a/app/views/note/_note_spacer.json.erb b/app/views/note/_note_spacer.json.erb deleted file mode 100644 index 7edb2fa5b..000000000 --- a/app/views/note/_note_spacer.json.erb +++ /dev/null @@ -1 +0,0 @@ -, diff --git a/app/views/note/list.json.erb b/app/views/note/list.json.erb deleted file mode 100644 index 48844789d..000000000 --- a/app/views/note/list.json.erb +++ /dev/null @@ -1,6 +0,0 @@ -{ - "type": "FeatureCollection", - "features": [ - <%= render :partial => "note", :collection => @notes, :spacer_template=> "note_spacer" -%> - ] -} diff --git a/app/views/note/list.json.jsonify b/app/views/note/list.json.jsonify new file mode 100644 index 000000000..cb75d41c4 --- /dev/null +++ b/app/views/note/list.json.jsonify @@ -0,0 +1,5 @@ +json.type "FeatureCollection" + +json.features(@notes) do |note| + json.ingest! render(:partial => "note", :object => note) +end diff --git a/app/views/note/read.json.jsonify b/app/views/note/read.json.jsonify new file mode 100644 index 000000000..3e5685fc0 --- /dev/null +++ b/app/views/note/read.json.jsonify @@ -0,0 +1 @@ +json.ingest! render(:partial => "note", :object => @note)