aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Florisson2013-07-02 09:56:08 +0200
committerMarc Florisson2013-07-02 09:56:08 +0200
commiteec54db17585f6c1e7354dcd8cf37749527071f1 (patch)
tree00cd7fa9da8ffbf3f0e54398d415f436a2cc48e4
parenta7977aee809c710736d94f3c615547eefffd01b3 (diff)
downloadchouette-core-eec54db17585f6c1e7354dcd8cf37749527071f1.tar.bz2
add exporters classes
-rw-r--r--app/exporters/chouette/kml/exporter.rb10
-rw-r--r--app/exporters/chouette/kml/line_exporter.rb20
2 files changed, 30 insertions, 0 deletions
diff --git a/app/exporters/chouette/kml/exporter.rb b/app/exporters/chouette/kml/exporter.rb
new file mode 100644
index 000000000..e033317d2
--- /dev/null
+++ b/app/exporters/chouette/kml/exporter.rb
@@ -0,0 +1,10 @@
+class Chouette::Kml::Exporter
+ def export(file, options = {})
+ if options.include?(:line)
+ Chouette::Kml::LineExporter.new( options[:line]).tap do |line_exporter|
+ line_exporter.save(file)
+ end
+ end
+ end
+end
+
diff --git a/app/exporters/chouette/kml/line_exporter.rb b/app/exporters/chouette/kml/line_exporter.rb
new file mode 100644
index 000000000..f74912a22
--- /dev/null
+++ b/app/exporters/chouette/kml/line_exporter.rb
@@ -0,0 +1,20 @@
+class Chouette::Kml::LineExporter
+ include ERB::Util
+ attr_accessor :line, :template
+
+ def initialize(line)
+ @line = line
+ @template = File.open('app/views/api/kml/lines/show.kml.erb' ){ |f| f.read }
+ end
+
+ def render()
+ ERB.new(@template).result(binding)
+ end
+
+ def save(file)
+ File.open(file, "w+") do |f|
+ f.write(render)
+ end
+ end
+end
+