Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 9 commits
  • 9 files changed
  • 0 commit comments
  • 5 contributors
View
2 app/assets/javascripts/gmaps4rails/gmaps4rails.openlayers.js.coffee
@@ -89,7 +89,7 @@ class @Gmaps4RailsOpenlayers extends Gmaps4Rails
style_mark.backgroundXOffset = args.shadow_anchor[0]
style_mark.backgroundYOffset = args.shadow_anchor[1]
- style_mark.graphicTitle = args.title
+ style_mark.graphicTitle = args.marker_title
marker = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(args.Lng, args.Lat),
null,
View
17 app/views/gmaps4rails/_gmaps4rails.html.erb
@@ -1,17 +0,0 @@
-<script type="text/javascript">
-<%=raw options.to_gmaps4rails %>
-</script>
-<% end %>
-
-<% case dom.map_provider %>
-<% when "mapquest" %>
-<div id="<%= dom.map_id %>" style="width:750px; height:475px;">
- <!-- TODO: change this style dynamically -->
-</div>
-<% when "bing" %>
- <div id="<%= dom.map_id %>" class="<%= dom.map_class %>"></div>
-<% else %>
-<div class="<%= dom.container_class %>">
- <div id="<%= dom.map_id %>" class="<%= dom.map_class %>"></div>
-</div>
-<% end %>
View
3 app/views/gmaps4rails/_gmaps4rails_libs.html.erb
@@ -1,2 +1,3 @@
<% content_for :scripts do %>
-<%= javascript_include_tag *js_dependencies %>
+ <%= javascript_include_tag *js_dependencies %>
+<% end %>
View
2 app/views/gmaps4rails/_gmaps4rails_libs.html.haml
@@ -0,0 +1,2 @@
+- content_for :scripts do
+ = javascript_include_tag *js_dependencies
View
15 lib/generators/gmaps4rails/install_generator.rb
@@ -5,7 +5,7 @@ class InstallGenerator < Rails::Generators::Base
desc 'Creates a Gmaps4rails initializer and copies the assets to the public folder.'
- class_option :views, :type => :boolean, :default => false, :desc => 'copy partials to app/views of Rails app'
+ class_option :views, :type => :string, :default => nil, :desc => 'copy partials to app/views of Rails app'
def copy_locale
if Rails::VERSION::MINOR >= 1
@@ -27,15 +27,18 @@ def copy_locale
end
def copy_views
- return unless copy_views?
- copy_file File.join(source_views_path, "_gmaps4rails_libs.html.erb"), File.join(destination_views_path, "_gmaps4rails_lib.html.erb")
- copy_file File.join(source_views_path, "_gmaps4rails.html.erb"), File.join(destination_views_path, "_gmaps4rails.html.erb")
+ return unless valid_template_type?
+ copy_file File.join(source_views_path, "_gmaps4rails_libs.html.#{template_type}"), File.join(destination_views_path, "_gmaps4rails_lib.html.#{template_type}")
end
protected
- def copy_views?
- options[:views]
+ def template_type
+ options[:views].to_s.to_sym
+ end
+
+ def valid_template_type?
+ [:erb, :haml].include? template_type
end
def source_views_path
View
47 lib/gmaps4rails/config.rb
@@ -0,0 +1,47 @@
+require 'singleton'
+
+module Gmaps4rails
+ def self.config
+ Config.instance
+ end
+
+ class Config
+ include Singleton
+
+ def options
+ yaml_loader.load
+ end
+
+ protected
+
+ def yaml_loader
+ @yaml_loader ||= YamlLoader.new
+ end
+
+ class YamlLoader
+ attr_writer :config_file, :config_path
+
+ def load
+ @load ||= HashWithIndifferentAccess.new load_yaml
+ end
+
+ def config_path
+ Rails.root.join 'config', config_file
+ end
+
+ def config_file
+ @config_file ||= 'gmaps4rails.yml'
+ end
+
+ protected
+
+ def load_yaml
+ @yaml ||= begin
+ YAML.load File.read(config_path)
+ rescue
+ {}
+ end
+ end
+ end
+ end
+end
View
69 lib/gmaps4rails/helper/gmaps4rails_helper.rb
@@ -12,29 +12,62 @@ def gmaps4rails(builder)
# full helper to pass all variables and their options
# @params [Hash] options is a Hash containing data and options. Example: { markers:{ data: @json, options: { do_clustering: true } } }
- def gmaps(options)
- gmaps_libs(options)
- render :partial => '/gmaps4rails/gmaps4rails',
- :locals => {
- :options => options_with_indifferent_access,
- :dom => view_helper.dom_attributes
- }
+ def gmaps(options = {})
+ options = Gmaps4rails.config.load.merge(options)
+
+ gmaps_libs(options) if options[:with_libs]
+
+ options_with_indifferent_access = options.with_indifferent_access
+ view_helper = Gmaps4rails::ViewHelper.new(options_with_indifferent_access)
+ gmaps4rails_map view_helper.dom_attributes, options_with_indifferent_access
+ end
+
+ def gmaps_libs(options = {})
+ options_with_indifferent_access = options.with_indifferent_access
+ view_helper = Gmaps4rails::ViewHelper.new(options_with_indifferent_access)
+
+ js_dependencies = Gmaps4rails.escape_js_url ? view_helper.js_dependencies_array : view_helper.js_dependencies_array.map(&:html_safe)
+
+ content_for :scripts do
+ javascript_include_tag(*js_dependencies)
+ end
+
+ # render partial: '/gmaps4rails/gmaps4rails_libs',
+ # :locals => {
+ # :js_dependencies => js_dependencies,
+ # :options => options_with_indifferent_access
+ # }
end
- def gmaps_libs(options)
+ def gmaps_libs_now(options = {})
options_with_indifferent_access = options.with_indifferent_access
view_helper = Gmaps4rails::ViewHelper.new(options_with_indifferent_access)
- js_dependencies = if Gmaps4rails.escape_js_url
- view_helper.js_dependencies_array
- else
- view_helper.js_dependencies_array.map(&:html_safe)
- end
-
- render 'gmaps4rails/gmaps4rails_libs',
- :locals => {
- :js_dependencies => js_dependencies
- }
+ js_dependencies = Gmaps4rails.escape_js_url ? view_helper.js_dependencies_array : view_helper.js_dependencies_array.map(&:html_safe)
+
+ javascript_include_tag(*js_dependencies)
end
+ protected
+
+ def gmaps4rails_map dom, options = {}
+ options.reverse_merge! :style => "width:750px; height:475px;"
+
+ map_script << content_tag(:script, :type => "text/javascript") do
+ raw(options.to_gmaps4rails).html_safe
+ end
+
+ map = case dom.map_provider.to_sym
+ when :mapquest
+ content_tag :div, nil, :id => dom.map_id, :style => options[:style]
+ when :bing
+ content_tag :div, nil, :id => dom.map_id, :class => dom.map_class
+ else
+ content_tag :div, :class => dom.container_class do
+ content_tag :div, nil, :id => dom.map_id, :class => dom.map_class
+ end
+ end
+
+ (map_script + map).html_safe
+ end
end
View
3 lib/gmaps4rails/js_builder.rb
@@ -21,6 +21,7 @@ def initialize(option_hash)
end
def create_js
+ # @js << "$(function() {"
@js << "#{gmap_id} = new #{ map_constructor };"
@js << "Gmaps.#{js_function_name} = function() {"
@@ -34,7 +35,7 @@ def create_js
@js << "#{gmap_id}.callback();"
@js << "};"
@js << "Gmaps.oldOnload = window.onload;\n window.onload = function() { Gmaps.triggerOldOnload(); Gmaps.loadMaps(); };" if load_map?
-
+ # @js << "}); // ready"
@js * ("\n")
end
View
10 lib/gmaps4rails/view_helper.rb
@@ -66,9 +66,9 @@ def get_vendor_scripts
when "mapquest" then @js_array << "#{MAPQUEST}?key=#{provider_key}"
when "bing" then @js_array << BING
else #case googlemaps which is the default
- @js_array << "#{GOOGLE}&sensor=false&key=#{provider_key}&libraries=geometry#{google_libraries}&#{google_map_i18n}"
+ @js_array << "#{GOOGLE}&sensor=false&client=#{client}&key=#{provider_key}&libraries=geometry#{google_libraries}&#{google_map_i18n}"
@js_array << "#{GOOGLE_EXT}tags/infobox/1.1.9/src/infobox_packed.js" if custom_infowindow_class
- @js_array << "#{GOOGLE_EXT}tags/markerclustererplus/2.0.9/src/markerclusterer_packed.js" if do_clustering
+ @js_array << "#{GOOGLE_EXT}tags/markerclustererplus/2.0.14/src/markerclusterer_packed.js" if do_clustering
@js_array << "#{GOOGLE_EXT}trunk/richmarker/src/richmarker-compiled.js" if rich_marker
end
end
@@ -111,6 +111,10 @@ def scripts
def provider_key
map_options.try(:[], :provider_key)
end
+
+ def client
+ map_options.try(:[], :client)
+ end
# when custom_infowindow_class is added in the marker_options,
#it means user wants to use the InfoBox googlemap's plugin
@@ -168,4 +172,4 @@ def container_class
end
-end
+end

No commit comments for this range

Something went wrong with that request. Please try again.