]> git.openstreetmap.org Git - rails.git/commitdiff
Use jsonify to create JSON for notes so that it is properly formatted
authorTom Hughes <tom@compton.nu>
Fri, 6 Jan 2012 00:24:51 +0000 (00:24 +0000)
committerTom Hughes <tom@compton.nu>
Fri, 6 Jan 2012 00:24:51 +0000 (00:24 +0000)
Gemfile
Gemfile.lock
app/views/note/_note.json.erb [deleted file]
app/views/note/_note.json.jsonify [new file with mode: 0644]
app/views/note/_note_comment.json.erb [deleted file]
app/views/note/_note_spacer.json.erb [deleted file]
app/views/note/list.json.erb [deleted file]
app/views/note/list.json.jsonify [new file with mode: 0644]
app/views/note/read.json.jsonify [new file with mode: 0644]

diff --git a/Gemfile b/Gemfile
index 08dafa0cc6e08029d2c358bccf77ed3ec7325384..0f867f3d55a566210665c7a14731e89e4bdccfee 100644 (file)
--- 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'
index 3343161f9531efc4da5d244daa4f12a9074f3c04..482d9c3edac768aea5309a05d2fd9602c3f969a0 100644 (file)
@@ -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 (file)
index 0d101f0..0000000
+++ /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 (file)
index 0000000..a6ef979
--- /dev/null
@@ -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 (file)
index 405a87d..0000000
+++ /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 (file)
index 7edb2fa..0000000
+++ /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 (file)
index 4884478..0000000
+++ /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 (file)
index 0000000..cb75d41
--- /dev/null
@@ -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 (file)
index 0000000..3e5685f
--- /dev/null
@@ -0,0 +1 @@
+json.ingest! render(:partial => "note", :object => @note)