]> git.openstreetmap.org Git - rails.git/commitdiff
Get returning of bugs as GPX files working
authorTom Hughes <tom@compton.nu>
Sat, 7 May 2011 13:53:30 +0000 (14:53 +0100)
committerTom Hughes <tom@compton.nu>
Sat, 7 May 2011 13:54:22 +0000 (14:54 +0100)
app/controllers/map_bugs_controller.rb
app/views/map_bugs/_bug.gpx.builder [new file with mode: 0644]
app/views/map_bugs/get_bugs.gpx.builder
app/views/map_bugs/read.gpx.builder [new file with mode: 0644]
config/initializers/mime_types.rb

index d1790a0dede39eada140bf1d46862e8a84b025b4..2de11ba755e49578e5c58c9ff2591a6e8d63e3a7 100644 (file)
@@ -47,7 +47,7 @@ class MapBugsController < ApplicationController
       format.js
       format.xml {render :template => 'map_bugs/get_bugs.xml'}
       format.json { render :json => @bugs.to_json(:methods => [:lat, :lon], :only => [:id, :status, :date_created], :include => { :map_bug_comment => { :only => [:commenter_name, :date_created, :comment]}}) }         
-#      format.gpx {render :template => 'map_bugs/get_bugs.gpx'}
+      format.gpx {render :template => 'map_bugs/get_bugs.gpx'}
     end
   end
 
@@ -166,6 +166,7 @@ class MapBugsController < ApplicationController
       format.rss
       format.xml
       format.json { render :json => @bug.to_json(:methods => [:lat, :lon], :only => [:id, :status, :date_created], :include => { :map_bug_comment => { :only => [:commenter_name, :date_created, :comment]}}) }          
+      format.gpx
     end
   end
 
@@ -200,7 +201,7 @@ class MapBugsController < ApplicationController
       format.js
       format.xml {render :template => 'map_bugs/get_bugs.xml'}
       format.json { render :json => @bugs.to_json(:methods => [:lat, :lon], :only => [:id, :status, :date_created], :include => { :map_bug_comment => { :only => [:commenter_name, :date_created, :comment]}}) }
-#      format.gpx {render :template => 'map_bugs/get_bugs.gpx'}
+      format.gpx {render :template => 'map_bugs/get_bugs.gpx'}
     end
   end
 
diff --git a/app/views/map_bugs/_bug.gpx.builder b/app/views/map_bugs/_bug.gpx.builder
new file mode 100644 (file)
index 0000000..18a84ba
--- /dev/null
@@ -0,0 +1,15 @@
+xml.wpt("lon" => bug.lon, "lat" => bug.lat) do
+  xml.desc do
+    xml.cdata! bug.flatten_comment("<hr />")
+  end
+
+  xml.extension do
+    if bug.status = "open"
+      xml.closed "0"
+    else
+      xml.closed "1"
+    end
+
+    xml.id bug.id
+  end
+end
index be7e9cf7aff5a0f7c81f5e99b3ef9f8ed51c391d..f543c1a021e5255921f0f12072952c5af0bea9ef 100644 (file)
@@ -1,23 +1,7 @@
 xml.instruct!
 
-
 xml.gpx("version" => "1.1", 
         "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
-           "xsi:schemaLocation" => "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd") do
-
-       for bug in @bugs
-      xml.wpt("lon" => bug.lon, "lat" => bug.lat) do
-               xml.desc do
-                       xml.cdata! bug.flatten_comment("<hr />")
-               end
-               xml.extension do
-                       if bug.status = "open"
-                               xml.closed "0"
-                       else
-                               xml.closed "1"
-                       end
-                       xml.id bug.id
-               end
-      end
-       end
+        "xsi:schemaLocation" => "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd") do
+  xml << render(:partial => "bug", :collection => @bugs)
 end
diff --git a/app/views/map_bugs/read.gpx.builder b/app/views/map_bugs/read.gpx.builder
new file mode 100644 (file)
index 0000000..0108a26
--- /dev/null
@@ -0,0 +1,7 @@
+xml.instruct!
+
+xml.gpx("version" => "1.1", 
+        "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
+        "xsi:schemaLocation" => "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd") do
+  xml << render(:partial => "bug", :object => @bug)
+end
index 72aca7e441e1855f8c7a7ac1f1cbe5d42cd1235b..18df05cf2c4f6ffb1be0c7e794cb7b7c4eb606b1 100644 (file)
@@ -1,5 +1,3 @@
-# Be sure to restart your server when you modify this file.
-
 # Add new mime types for use in respond_to blocks:
-# Mime::Type.register "text/richtext", :rtf
-# Mime::Type.register_alias "text/html", :iphone
+
+Mime::Type.register "application/gpx+xml", :gpx