lib/gmaps4rails/js_builder.rb in gmaps4rails-1.5.2 vs lib/gmaps4rails/js_builder.rb in gmaps4rails-1.5.3
- old
+ new
@@ -1,11 +1,6 @@
module Gmaps4rails
-
- def Gmaps4rails.create_js_from_hash(hash)
- ::Gmaps4rails::JsBuilder.new(hash).create_js
- end
-
class JsBuilder
DEFAULT_MAP_ID = "map"
DATA_KEYS = [:markers, :polylines, :polygons, :circles, :direction, :kml]
@@ -92,13 +87,17 @@
end
class Datum
# example:
# - name: :markers
- # - hash: { :data => json, :options => hash }
+ # - hash: { :data => json, :options => hash }
+
+ delegate :options, :data, :to => :@element_info
+
def initialize(gmap_id, name, hash)
- @gmap_id, @hash, @name, @js = gmap_id, hash, name, Array.new
+ @gmap_id, @name, @js = gmap_id, name, Array.new
+ @element_info = OpenStruct.new(hash)
end
def create_js
if @name.to_sym == :direction
create_direction_js
@@ -106,20 +105,20 @@
create_standard_js
end
end
def create_standard_js
- @js << "#{@gmap_id}.#{@name} = #{value};"
+ @js << "#{@gmap_id}.#{@name} = #{data};"
set_configuration_variables
@js << "#{@gmap_id}.create_#{@name}();"
end
def create_direction_js
- @js << "#{@gmap_id}.direction_conf.origin = '#{value["from"]}';"
- @js << "#{@gmap_id}.direction_conf.destination = '#{value["to"]}';"
+ @js << "#{@gmap_id}.direction_conf.origin = '#{data["from"]}';"
+ @js << "#{@gmap_id}.direction_conf.destination = '#{data["to"]}';"
set_direction_variables
@js << "#{@gmap_id}.create_direction();"
end
@@ -148,16 +147,9 @@
@js << "#{@gmap_id}.direction_conf.#{option_key} = #{option_value.to_json};"
end
end
end
- def options
- @hash[:options]
- end
-
- def value
- @hash[:data]
- end
end
end
end
\ No newline at end of file