gmaps4rails 1.1.7 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,10 +13,11 @@ module Gmaps4rails
13
13
  #try to geocode
14
14
  begin
15
15
  coordinates = Gmaps4rails.geocode(self.send(gmaps4rails_options[:address]), gmaps4rails_options[:language])
16
- rescue GeocodeStatus, GeocodeInvalidQuery #address was invalid, add error to base.
16
+ rescue GeocodeStatus, GeocodeInvalidQuery => e #address was invalid, add error to base.
17
+ Rails.logger.warn(e)
17
18
  errors[gmaps4rails_options[:address]] << gmaps4rails_options[:msg] if gmaps4rails_options[:validation]
18
19
  rescue GeocodeNetStatus => e #connection error, No need to prevent save.
19
- logger.warn(e)
20
+ Rails.logger.warn(e)
20
21
  #TODO add customization here?
21
22
  else #if no exception, save the values
22
23
  self.send(gmaps4rails_options[:lng_column]+"=", coordinates.first[:lng]) if self.respond_to?(gmaps4rails_options[:lng_column]+"=")
@@ -14,47 +14,101 @@ module Gmaps4rails
14
14
 
15
15
  # Creates the json related to one Object (only tried ActiveRecord objects)
16
16
  # This json will contian the marker's attributes of the object
17
-
17
+ mattr_accessor :json_from_block
18
+
18
19
  def Gmaps4rails.create_json(object, &block)
19
- unless object.send(object.gmaps4rails_options[:lat_column]).blank? && object.send(object.gmaps4rails_options[:lng_column]).blank?
20
- "{#{Gmaps4rails.description(object)}#{Gmaps4rails.title(object)}#{Gmaps4rails.sidebar(object)}\"lng\": \"#{object.send(object.gmaps4rails_options[:lng_column])}\", \"lat\": \"#{object.send(object.gmaps4rails_options[:lat_column])}\"#{Gmaps4rails.picture(object)}#{Gmaps4rails.block_handling(object, &block)}},\n"
21
- end
20
+ @json_from_block = String.new
21
+ unless object.send(object.gmaps4rails_options[:lat_column]).blank? && object.send(object.gmaps4rails_options[:lng_column]).blank?
22
+ Gmaps4rails.block_handling(object, &block)
23
+ "{#{description(object)}#{get_title(object)}#{get_sidebar(object)}#{marker_picture(object)}#{@json_from_block}\"lng\": \"#{object.send(object.gmaps4rails_options[:lng_column])}\", \"lat\": \"#{object.send(object.gmaps4rails_options[:lat_column])}\"},\n"
24
+ end
22
25
  end
23
26
 
24
27
  # execute block if provided so that it's included in the json string
25
28
  def Gmaps4rails.block_handling(object, &block)
26
- ", " + yield(object) if block_given?
29
+ block_result = yield(object, ::Gmaps4rails) if block_given?
30
+ Gmaps4rails.json(block_result) if block_result.is_a? String
27
31
  end
28
32
 
29
- # Returns description if gmaps4rails_infowindow is defined in the model
30
- def Gmaps4rails.description(object)
31
- return "\"description\": \"#{object.gmaps4rails_infowindow}\", " if object.respond_to?("gmaps4rails_infowindow")
33
+ def Gmaps4rails.json(string)
34
+ @json_from_block += "#{gsub_string(string)}, "
35
+ return true
32
36
  end
33
37
 
34
- # Returns title if gmaps4rails_title is defined in the model
38
+ ################################################
39
+ # in use to create json from model
40
+ def Gmaps4rails.marker_picture(object)
41
+ create_js_for_picture object.gmaps4rails_marker_picture if object.respond_to?("gmaps4rails_marker_picture")
42
+ end
43
+
44
+ # in use in block
45
+ def Gmaps4rails.picture(hash)
46
+ @json_from_block += create_js_for_picture hash
47
+ return true
48
+ end
35
49
 
36
- def Gmaps4rails.title(object)
37
- return "\"title\": \"#{object.gmaps4rails_title}\", " if object.respond_to?("gmaps4rails_title")
50
+ # Returns picture js from a hash
51
+ def Gmaps4rails.create_js_for_picture(raw_hash)
52
+ hash = raw_hash.with_indifferent_access
53
+ result = hash.map do |k,v|
54
+ #specific case, anchors are array and should be interpreted this way
55
+ if k.include? "_anchor"
56
+ "\"#{k}\": [#{v[0]}, #{v[1]}]"
57
+ else
58
+ "\"#{k}\": \"#{v}\""
59
+ end
60
+ end.join(", ")
61
+ end
62
+ ##################################################
63
+ # in use in block
64
+ def Gmaps4rails.infowindow(string)
65
+ @json_from_block += create_js_for_infowindow string
66
+ return true
38
67
  end
39
68
 
40
- # Returns sidebar content if gmaps4rails_sidebar is defined in the model
69
+ # in use to create json from model
70
+ def Gmaps4rails.description(object)
71
+ create_js_for_infowindow object.gmaps4rails_infowindow if object.respond_to?("gmaps4rails_infowindow")
72
+ end
41
73
 
42
- def Gmaps4rails.sidebar(object)
43
- return "\"sidebar\": \"#{object.gmaps4rails_sidebar}\"," if object.respond_to?("gmaps4rails_sidebar")
74
+ def Gmaps4rails.create_js_for_infowindow(string)
75
+ "\"description\": \"#{gsub_string(string)}\", "
44
76
  end
45
77
 
46
- # Returns picture options if gmaps4rails_marker_picture is defined in the model
47
- def Gmaps4rails.picture(object)
48
- if object.respond_to?("gmaps4rails_marker_picture")
49
- ", " + object.gmaps4rails_marker_picture.map do |k,v|
50
- #specific case, anchors are array and should be interpreted this way
51
- if k.include? "_anchor"
52
- "\"#{k}\": [#{v[0]}, #{v[1]}]"
53
- else
54
- "\"#{k}\": \"#{v}\""
55
- end
56
- end.join(", ")
57
- end
78
+ ##################################################
79
+ # in use in block
80
+ def Gmaps4rails.title(string)
81
+ create_js_for_title string
82
+ end
83
+
84
+ # in use to create json from model
85
+ def Gmaps4rails.get_title(object)
86
+ create_js_for_title object.gmaps4rails_title if object.respond_to?("gmaps4rails_title")
87
+ end
88
+
89
+ def Gmaps4rails.create_js_for_title(string)
90
+ "\"title\": \"#{gsub_string(string)}\", "
91
+ end
92
+ ##################################################
93
+
94
+ # in use in block
95
+ def Gmaps4rails.sidebar(string)
96
+ create_js_for_sidebar string
97
+ end
98
+
99
+ # in use to create json from model
100
+ def Gmaps4rails.get_sidebar(object)
101
+ create_js_for_sidebar object.gmaps4rails_sidebar if object.respond_to?("gmaps4rails_sidebar")
102
+ end
103
+
104
+ def Gmaps4rails.create_js_for_sidebar(string)
105
+ "\"sidebar\": \"#{gsub_string(string)}\", "
106
+ end
107
+ ##################################################
108
+
109
+
110
+ def Gmaps4rails.gsub_string(string)
111
+ string #you could do override with something like: string.gsub(/\n/, '').gsub(/"/, '\"')
58
112
  end
59
113
 
60
114
  # This method geocodes an address using the GoogleMaps webservice
@@ -270,7 +324,6 @@ module Gmaps4rails
270
324
  result << "#{map_id}.callback();"
271
325
 
272
326
  result << "};"
273
- # result << "debugger;"
274
327
  if hash[:last_map].nil? || hash[:last_map] == true
275
328
  result << "window.onload = function() { Gmaps.loadMaps(); };"
276
329
  end
metadata CHANGED
@@ -1,49 +1,41 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: gmaps4rails
3
- version: !ruby/object:Gem::Version
4
- hash: 29
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 1
9
- - 7
10
- version: 1.1.7
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Benjamin Roth
14
9
  - David Ruyer
15
10
  autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
-
19
- date: 2011-09-22 00:00:00 Z
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
13
+ date: 2011-09-30 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: crack
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &2152401340 !ruby/object:Gem::Requirement
25
18
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
33
23
  type: :runtime
34
- version_requirements: *id001
35
- description: "Enables easy display of items (taken from a Rails 3 model) on a Google Maps (JS API V3), OpenLayers, Mapquest and Bing. Geocoding + Directions included. Provides much options: markers customization, infowindows, auto-adjusted zoom, polylines, polygons, circles etc... See wiki on github for full description and examples."
36
- email:
24
+ prerelease: false
25
+ version_requirements: *2152401340
26
+ description: ! 'Enables easy display of items (taken from a Rails 3 model) on a Google
27
+ Maps (JS API V3), OpenLayers, Mapquest and Bing. Geocoding + Directions included.
28
+ Provides much options: markers customization, infowindows, auto-adjusted zoom, polylines,
29
+ polygons, circles etc... See wiki on github for full description and examples.'
30
+ email:
37
31
  - apnea.diving.deep@gmail.com
38
32
  - david.ruyer@gmail.com
39
33
  executables: []
40
-
41
34
  extensions: []
42
-
43
- extra_rdoc_files:
35
+ extra_rdoc_files:
44
36
  - LICENSE.txt
45
37
  - README.rdoc
46
- files:
38
+ files:
47
39
  - app/assets/javascripts/gmaps4rails/all_apis.js
48
40
  - app/assets/javascripts/gmaps4rails/bing.js
49
41
  - app/assets/javascripts/gmaps4rails/gmaps4rails.base.js.coffee
@@ -74,36 +66,27 @@ files:
74
66
  - README.rdoc
75
67
  homepage: http://github.com/apneadiving/Google-Maps-for-Rails
76
68
  licenses: []
77
-
78
69
  post_install_message:
79
70
  rdoc_options: []
80
-
81
- require_paths:
71
+ require_paths:
82
72
  - lib
83
- required_ruby_version: !ruby/object:Gem::Requirement
73
+ required_ruby_version: !ruby/object:Gem::Requirement
84
74
  none: false
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- hash: 3
89
- segments:
90
- - 0
91
- version: "0"
92
- required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
80
  none: false
94
- requirements:
95
- - - ">="
96
- - !ruby/object:Gem::Version
97
- hash: 3
98
- segments:
99
- - 0
100
- version: "0"
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
101
85
  requirements: []
102
-
103
86
  rubyforge_project:
104
87
  rubygems_version: 1.8.6
105
88
  signing_key:
106
89
  specification_version: 3
107
- summary: Enables easy display of items (taken from a Rails 3 model) on a Google Maps (JS API V3), OpenLayers, Mapquest and Bing. Geocoding + Directions included.
90
+ summary: Enables easy display of items (taken from a Rails 3 model) on a Google Maps
91
+ (JS API V3), OpenLayers, Mapquest and Bing. Geocoding + Directions included.
108
92
  test_files: []
109
-