gmaps4rails 1.4.8 → 1.5.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +11 -0
- data/.travis.yml +10 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +175 -0
- data/Guardfile +38 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +26 -37
- data/Rakefile +4 -0
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.base.js.coffee +40 -34
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.googlemaps.js.coffee +4 -2
- data/app/views/gmaps4rails/_gmaps4rails.html.erb +13 -12
- data/gmaps4rails.gemspec +38 -0
- data/lib/gmaps4rails.rb +0 -8
- data/lib/gmaps4rails/acts_as_gmappable.rb +55 -33
- data/lib/gmaps4rails/base.rb +7 -12
- data/lib/gmaps4rails/helper/gmaps4rails_helper.rb +16 -42
- data/lib/gmaps4rails/js_builder.rb +121 -0
- data/lib/gmaps4rails/json_builder.rb +127 -0
- data/lib/gmaps4rails/version.rb +3 -0
- data/lib/gmaps4rails/view_helper.rb +171 -0
- data/lib/tasks/gmaps4rails_tasks.rake +4 -0
- data/lib/tasks/jasmine.rake +8 -0
- data/public/javascripts/gmaps4rails/gmaps4rails.base.js +81 -30
- data/public/javascripts/gmaps4rails/gmaps4rails.bing.js +34 -11
- data/public/javascripts/gmaps4rails/gmaps4rails.googlemaps.js +45 -21
- data/public/javascripts/gmaps4rails/gmaps4rails.mapquest.js +33 -14
- data/public/javascripts/gmaps4rails/gmaps4rails.openlayers.js +33 -20
- data/spec/base/base_spec.rb +185 -0
- data/spec/base/geocoding_spec.rb +17 -0
- data/spec/dummy/.gitignore +2 -0
- data/spec/dummy/.rspec +1 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/assets/stylesheets/gmaps4rails.css +24 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/users_controller.rb +96 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/models/user.rb +9 -0
- data/spec/dummy/app/views/layouts/application.html.erb +16 -0
- data/spec/dummy/app/views/users/_form.html.erb +37 -0
- data/spec/dummy/app/views/users/_my_template.html.erb +2 -0
- data/spec/dummy/app/views/users/_my_template2.html.erb +1 -0
- data/spec/dummy/app/views/users/ajax_data.js.erb +2 -0
- data/spec/dummy/app/views/users/ajax_test.html.erb +22 -0
- data/spec/dummy/app/views/users/edit.html.erb +6 -0
- data/spec/dummy/app/views/users/index.html.erb +238 -0
- data/spec/dummy/app/views/users/new.html.erb +5 -0
- data/spec/dummy/app/views/users/show.html.erb +30 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +62 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +60 -0
- data/spec/dummy/db/migrate/20120408170155_create_users.rb +16 -0
- data/spec/dummy/db/schema.rb +29 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/javascripts/Player.js +22 -0
- data/spec/dummy/public/javascripts/Song.js +7 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/factories/user_factory.rb +23 -0
- data/spec/javascripts/basic_methods_spec.js +103 -0
- data/spec/javascripts/helpers/.gitkeep +0 -0
- data/spec/javascripts/helpers/SpecHelper.js +87 -0
- data/spec/javascripts/map_spec.js +49 -0
- data/spec/javascripts/markers_methods_spec.js +368 -0
- data/spec/javascripts/mocks_spec.js +27 -0
- data/spec/javascripts/support/jasmine.yml +76 -0
- data/spec/javascripts/support/jasmine_config.rb +23 -0
- data/spec/javascripts/support/jasmine_runner.rb +20 -0
- data/spec/launchers/all_but_requests.rb +0 -0
- data/spec/launchers/all_specs.rb +0 -0
- data/spec/launchers/requests.rb +0 -0
- data/spec/models/user_spec.rb +447 -0
- data/spec/spec_helper.rb +44 -0
- data/spec/support/geocoding.rb +14 -0
- data/spec/support/matchers.rb +43 -0
- metadata +364 -31
- data/LICENSE.txt +0 -21
- data/app/assets/javascripts/gmaps4rails/all_apis.js +0 -5
- data/app/assets/javascripts/gmaps4rails/bing.js +0 -2
- data/app/assets/javascripts/gmaps4rails/googlemaps.js +0 -2
- data/app/assets/javascripts/gmaps4rails/mapquest.js +0 -2
- data/app/assets/javascripts/gmaps4rails/openlayers.js +0 -2
- data/app/views/gmaps4rails/_html.html.erb +0 -12
- data/app/views/gmaps4rails/_scripts.html.erb +0 -37
- data/lib/gmaps4rails/js_handler.rb +0 -112
- data/lib/gmaps4rails/json_handler.rb +0 -116
- data/public/images/marker.png +0 -0
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2010 Benjamin Roth
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
@@ -1,12 +0,0 @@
|
|
1
|
-
<% case map_options.try(:[], :provider) %>
|
2
|
-
<% when "mapquest" %>
|
3
|
-
<div id="<%= gmaps4rails_map_id(map_options) %>" style="width:750px; height:475px;">
|
4
|
-
<!-- TODO: change this style dynamically -->
|
5
|
-
</div>
|
6
|
-
<% when "bing" %>
|
7
|
-
<div id="<%= gmaps4rails_map_id(map_options) %>" class="<%= gmaps4rails_map_class(map_options) %>"></div>
|
8
|
-
<% else %>
|
9
|
-
<div class="<%= gmaps4rails_container_class(map_options) %>">
|
10
|
-
<div id="<%= gmaps4rails_map_id(map_options) %>" class="<%= gmaps4rails_map_class(map_options) %>"></div>
|
11
|
-
</div>
|
12
|
-
<% end %>
|
@@ -1,37 +0,0 @@
|
|
1
|
-
<% if enable_js == true && scripts.try(:to_sym) != :none %>
|
2
|
-
<% case map_options.try(:[], :provider) %>
|
3
|
-
<% when "openlayers" %>
|
4
|
-
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
|
5
|
-
<% when "mapquest" %>
|
6
|
-
<script src="http://mapquestapi.com/sdk/js/v6.0.0/mqa.toolkit.js?key=<%= map_options.try(:[], :provider_key) %>"></script>
|
7
|
-
<% when "bing" %>
|
8
|
-
<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
|
9
|
-
<% else %>
|
10
|
-
<script type="text/javascript" src="//maps.google.com/maps/api/js?v=3.8&sensor=false&libraries=geometry<%= gmaps4rails_js_libraries(map_options.try(:[], :libraries)) %>&<%= gmaps4rails_map_language(map_options) %>"></script>
|
11
|
-
<% if marker_options.try(:[], :custom_infowindow_class) %>
|
12
|
-
<script type="text/javascript" src="//google-maps-utility-library-v3.googlecode.com/svn/tags/infobox/1.1.9/src/infobox_packed.js"></script>
|
13
|
-
<% end %>
|
14
|
-
<% if marker_options.try(:[], :do_clustering) %>
|
15
|
-
<script type="text/javascript" src="//google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.5/src/markerclusterer_packed.js"></script>
|
16
|
-
<% end %>
|
17
|
-
<% if marker_options.try(:[], :rich_marker) %>
|
18
|
-
<script type="text/javascript" src="//google-maps-utility-library-v3.googlecode.com/svn/trunk/richmarker/src/richmarker-compiled.js"></script>
|
19
|
-
<% end %>
|
20
|
-
<% end %>
|
21
|
-
|
22
|
-
<% unless gmaps4rails_pipeline_enabled? %>
|
23
|
-
<% unless scripts.try(:to_sym) == :api %>
|
24
|
-
<%= javascript_include_tag 'gmaps4rails/gmaps4rails.base.js' %>
|
25
|
-
<% end %>
|
26
|
-
<% case map_options.try(:[], :provider) %>
|
27
|
-
<% when "openlayers" %>
|
28
|
-
<%= javascript_include_tag 'gmaps4rails/gmaps4rails.openlayers.js' %>
|
29
|
-
<% when "mapquest" %>
|
30
|
-
<%= javascript_include_tag 'gmaps4rails/gmaps4rails.mapquest.js' %>
|
31
|
-
<% when "bing" %>
|
32
|
-
<%= javascript_include_tag 'gmaps4rails/gmaps4rails.bing.js' %>
|
33
|
-
<% else %>
|
34
|
-
<%= javascript_include_tag 'gmaps4rails/gmaps4rails.googlemaps.js' %>
|
35
|
-
<% end %>
|
36
|
-
<% end %>
|
37
|
-
<% end %>
|
@@ -1,112 +0,0 @@
|
|
1
|
-
module Gmaps4rails
|
2
|
-
|
3
|
-
DEFAULT_MAP_ID = "map"
|
4
|
-
|
5
|
-
def Gmaps4rails.js_function_name(hash)
|
6
|
-
"load_" + Gmaps4rails.get_map_id(hash[:map_options])
|
7
|
-
end
|
8
|
-
|
9
|
-
def Gmaps4rails.get_map_id(hash)
|
10
|
-
hash.nil? || hash[:id].nil? ? DEFAULT_MAP_ID : hash[:id]
|
11
|
-
end
|
12
|
-
|
13
|
-
def Gmaps4rails.get_constructor(hash)
|
14
|
-
hash.nil? || hash[:provider].nil? ? "Gmaps4RailsGoogle()" : "Gmaps4Rails#{hash[:provider].capitalize}()"
|
15
|
-
end
|
16
|
-
|
17
|
-
def Gmaps4rails.create_map_js(map_hash, map_id)
|
18
|
-
output = Array.new
|
19
|
-
skipped_keys = [:class, :container_class]
|
20
|
-
map_hash.each do |option_k, option_v|
|
21
|
-
unless skipped_keys.include? option_k.to_sym
|
22
|
-
case option_k.to_sym
|
23
|
-
when :bounds, :raw #particular case, render the content unescaped
|
24
|
-
output << "#{map_id}.map_options.#{option_k} = #{option_v};"
|
25
|
-
else
|
26
|
-
output << "#{map_id}.map_options.#{option_k} = #{Gmaps4rails.filter option_v};"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
output
|
31
|
-
end
|
32
|
-
|
33
|
-
def Gmaps4rails.create_general_js(hash, map_id, category)
|
34
|
-
output = Array.new
|
35
|
-
output << "#{map_id}.#{category} = #{hash[:data]};"
|
36
|
-
hash[:options] ||= Array.new
|
37
|
-
hash[:options].each do |option_k, option_v|
|
38
|
-
if option_k.to_sym == :raw
|
39
|
-
output << "#{map_id}.#{category}_conf.#{option_k} = #{option_v};"
|
40
|
-
else
|
41
|
-
output << "#{map_id}.#{category}_conf.#{option_k} = #{Gmaps4rails.filter option_v};"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
output << "#{map_id}.create_#{category}();"
|
45
|
-
output
|
46
|
-
end
|
47
|
-
|
48
|
-
def Gmaps4rails.create_direction_js(hash, map_id)
|
49
|
-
output = Array.new
|
50
|
-
output << "#{map_id}.direction_conf.origin = '#{hash["data"]["from"]}';"
|
51
|
-
output << "#{map_id}.direction_conf.destination = '#{hash["data"]["to"]}';"
|
52
|
-
hash[:options] ||= Array.new
|
53
|
-
hash[:options].each do |option_k, option_v|
|
54
|
-
if option_k.to_sym == :waypoints
|
55
|
-
waypoints = Array.new
|
56
|
-
option_v.each do |waypoint|
|
57
|
-
waypoints << { "location" => waypoint, "stopover" => true }.to_json
|
58
|
-
end
|
59
|
-
output << "#{map_id}.direction_conf.waypoints = [#{waypoints * (",")}];"
|
60
|
-
else #option_k != "waypoint"
|
61
|
-
output << "#{map_id}.direction_conf.#{option_k} = #{Gmaps4rails.filter option_v};"
|
62
|
-
end
|
63
|
-
end #end .each
|
64
|
-
output << "#{map_id}.create_direction();"
|
65
|
-
output
|
66
|
-
end
|
67
|
-
|
68
|
-
#the variable 'hash' must have the following structure
|
69
|
-
#{
|
70
|
-
# :map_options => hash,
|
71
|
-
# :markers => { :data => json, :options => hash },
|
72
|
-
# :polylines => { :data => json, :options => hash },
|
73
|
-
# :polygons => { :data => json, :options => hash },
|
74
|
-
# :circles => { :data => json, :options => hash },
|
75
|
-
# :direction => { :data => hash, :options => hash },
|
76
|
-
# :kml => { :data => json, :options => hash }
|
77
|
-
#}
|
78
|
-
#should be with only symbol keys or with indifferent access
|
79
|
-
def Gmaps4rails.create_js_from_hash(hash)
|
80
|
-
result = Array.new
|
81
|
-
map_id = "Gmaps." + Gmaps4rails.get_map_id(hash[:map_options])
|
82
|
-
|
83
|
-
#means we are creating a new map
|
84
|
-
result << "#{map_id} = new #{Gmaps4rails.get_constructor hash[:map_options] }" + ";"
|
85
|
-
result << "Gmaps.#{Gmaps4rails.js_function_name hash } = function() {"
|
86
|
-
result << Gmaps4rails.create_map_js(hash[:map_options], map_id) unless hash[:map_options].nil?
|
87
|
-
result << "#{map_id}.initialize();"
|
88
|
-
|
89
|
-
hash.each do |category, content| #loop through options hash
|
90
|
-
skipped_categories = [:map_options, :last_map, :scripts]
|
91
|
-
unless skipped_categories.include? category.to_sym
|
92
|
-
if category.to_sym == :direction
|
93
|
-
result << Gmaps4rails.create_direction_js(content, map_id)
|
94
|
-
else
|
95
|
-
result << Gmaps4rails.create_general_js(content, map_id, category)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
result << "#{map_id}.adjustMapToBounds();"
|
100
|
-
result << "#{map_id}.callback();"
|
101
|
-
|
102
|
-
result << "};"
|
103
|
-
if hash[:last_map].nil? || hash[:last_map] == true
|
104
|
-
result << "window.onload = function() { Gmaps.loadMaps(); };"
|
105
|
-
end
|
106
|
-
|
107
|
-
result * ('
|
108
|
-
')
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
112
|
-
|
@@ -1,116 +0,0 @@
|
|
1
|
-
module Gmaps4rails
|
2
|
-
|
3
|
-
mattr_accessor :json_hash, :custom_json, :object
|
4
|
-
|
5
|
-
def Gmaps4rails.create_json(object, &block)
|
6
|
-
@object, @json_hash, @custom_json = object, Hash.new, nil
|
7
|
-
if compliant?
|
8
|
-
handle_block(&block) if block_given?
|
9
|
-
handle_model_methods
|
10
|
-
return_json
|
11
|
-
else
|
12
|
-
nil
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def Gmaps4rails.infowindow(string)
|
17
|
-
@json_hash[:description] = string
|
18
|
-
true
|
19
|
-
end
|
20
|
-
|
21
|
-
def Gmaps4rails.title(string)
|
22
|
-
@json_hash[:title] = string
|
23
|
-
true
|
24
|
-
end
|
25
|
-
|
26
|
-
def Gmaps4rails.sidebar(string)
|
27
|
-
@json_hash[:sidebar] = string
|
28
|
-
true
|
29
|
-
end
|
30
|
-
|
31
|
-
def Gmaps4rails.json(json)
|
32
|
-
return @json_hash.merge! json if json.is_a? Hash
|
33
|
-
true
|
34
|
-
end
|
35
|
-
|
36
|
-
def Gmaps4rails.picture(hash)
|
37
|
-
@json_hash.merge! hash
|
38
|
-
true
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def Gmaps4rails.model_attributes
|
44
|
-
{
|
45
|
-
:description => :gmaps4rails_infowindow,
|
46
|
-
:title => :gmaps4rails_title,
|
47
|
-
:sidebar => :gmaps4rails_sidebar,
|
48
|
-
:marker_picture => :gmaps4rails_marker_picture,
|
49
|
-
:lat => @object.gmaps4rails_options[:lat_column],
|
50
|
-
:lng => @object.gmaps4rails_options[:lng_column]
|
51
|
-
}
|
52
|
-
end
|
53
|
-
|
54
|
-
def Gmaps4rails.handle_model_methods
|
55
|
-
model_attributes.each do |json_name, method_name|
|
56
|
-
if @object.respond_to? method_name
|
57
|
-
if json_name == :marker_picture
|
58
|
-
@json_hash.merge! @object.send(method_name)
|
59
|
-
else
|
60
|
-
@json_hash[json_name] = @object.send(method_name)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
# returns the proper json
|
67
|
-
# three cases here:
|
68
|
-
# - no custom json provided
|
69
|
-
# - custom json provided as a hash (marker.json { :id => user.id }) => merge hashes then create json
|
70
|
-
# - custom json provided as string (marker.json {"\"id\": #{user.id}" } => create json from hash then insert string inside
|
71
|
-
def Gmaps4rails.return_json
|
72
|
-
return @json_hash.to_json if @custom_json.nil?
|
73
|
-
if @custom_json.is_a? Hash
|
74
|
-
@json_hash.merge! @custom_json
|
75
|
-
return @json_hash.to_json
|
76
|
-
elsif @custom_json.is_a? String
|
77
|
-
output = @json_hash.to_json
|
78
|
-
return output.insert(1, @custom_json + ",")
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def Gmaps4rails.compliant?
|
83
|
-
!(@object.send(@object.gmaps4rails_options[:lat_column]).blank? && @object.send(@object.gmaps4rails_options[:lng_column]).blank?)
|
84
|
-
end
|
85
|
-
|
86
|
-
# the to_gmaps4rails method accepts a block to customize:
|
87
|
-
# - infowindow
|
88
|
-
# - picture
|
89
|
-
# - title
|
90
|
-
# - sidebar
|
91
|
-
# - json
|
92
|
-
#
|
93
|
-
# This works this way:
|
94
|
-
# @json = User.all.to_gmaps4rails do |user, marker|
|
95
|
-
# marker.infowindow render_to_string(:partial => "/users/my_template", :locals => { :object => user}).gsub(/\n/, '').gsub(/"/, '\"')
|
96
|
-
# marker.picture({
|
97
|
-
# :picture => "http://www.blankdots.com/img/github-32x32.png",
|
98
|
-
# :width => "32",
|
99
|
-
# :height => "32"
|
100
|
-
# })
|
101
|
-
# marker.title "i'm the title"
|
102
|
-
# marker.sidebar "i'm the sidebar"
|
103
|
-
# marker.json({ :id => user.id })
|
104
|
-
# end
|
105
|
-
#
|
106
|
-
# For backward compability, a mere string could be passed:
|
107
|
-
# @json = User.all.to_gmaps4rails do |user, marker|
|
108
|
-
# "\"id\": #{user.id}"
|
109
|
-
# end
|
110
|
-
#
|
111
|
-
def Gmaps4rails.handle_block(&block)
|
112
|
-
block_result = yield(@object, ::Gmaps4rails)
|
113
|
-
@custom_json = block_result unless block_result == true
|
114
|
-
end
|
115
|
-
|
116
|
-
end
|
data/public/images/marker.png
DELETED
Binary file
|