gmaps4rails 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc ADDED
File without changes
@@ -0,0 +1,14 @@
1
+ module Gmaps4rails
2
+ class GmapsController < ApplicationController
3
+ #unloadable
4
+ #layout 'gmaps4rails' # this allows you to have a gem-wide layout
5
+
6
+ def index
7
+ @model = params["model"]
8
+ if @model.constantize.is_gmappable? == true
9
+ @objects = @model.constantize.gmaps4rails_filter(params["filter"], params["options"])
10
+ end
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,2 @@
1
+ ## Look in lib/application_helper.rb
2
+ ## I can't figure out how to get it included unless I put it that directory
@@ -0,0 +1,7 @@
1
+ module Gmaps4rails
2
+ module GmapsHelper
3
+ def gmaps_sanitize(entity)
4
+ entity.nil? ? "" : entity
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ module Gmaps4rails
2
+ class Gmaps < ActiveRecord::Base
3
+ set_table_name "gmaps4rails_widgets"
4
+
5
+ def make
6
+ puts "widget made"
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ <% content_for(:head) do %>
2
+ <meta name="viewport" content="initial-scale=1.0, user-scalable=yes" />
3
+ <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"> </script>
4
+ <script type="text/javascript" src="/javascripts/gmaps4rails.js"> </script>
5
+ <% end %>
6
+
7
+ <div id="gmaps4rails_canvas" style="width:100%; height:100%"></div>
8
+
@@ -0,0 +1 @@
1
+ <%= debug @objects%>
@@ -0,0 +1,54 @@
1
+ xml.instruct! :xml, :version=>"1.0"
2
+ xml.kml do
3
+ xml.Document do
4
+ if @objects.first.respond_to?('gmaps4rails_marker')
5
+ xml.Style('id' => 'specmarker') do
6
+ xml.IconStyle do
7
+ xml.Icon "<href>" + @objects.first.gmaps4rails_marker + "</href>"
8
+ end
9
+ end
10
+ end
11
+
12
+ # <Style id="highlightPlacemark">
13
+ # <IconStyle>
14
+ # <Icon>
15
+ # <href>http://maps.google.com/mapfiles/kml/paddle/red-stars.png</href>
16
+ # </Icon>
17
+ # </IconStyle>
18
+ # </Style>
19
+
20
+ if @objects.respond_to?('gmaps4rails_info')
21
+ @objects.each do |object|
22
+
23
+ xml.Placemark do
24
+ desc = object.gmaps4rails_info
25
+ lat = object.gmaps4rails_latitude.nil? ? "" : object.gmaps4rails_latitude
26
+ long = object.gmaps4rails_longitude.nil? ? "" : object.gmaps4rails_longitude
27
+ xml.name "click me"
28
+ xml.styleUrl "specmarker"
29
+ xml.description desc
30
+ xml.Point do
31
+ str = long + "," + lat + ",0"
32
+ xml.coordinates(str)
33
+ end
34
+ end #placemark
35
+ end
36
+ else
37
+ @objects.each do |object|
38
+ xml.Placemark do
39
+ desc = object.gmaps4rails_picture.nil? ? "" : '<img width="40" heigth="40" src="' + object.gmaps4rails_picture + '">'
40
+ desc += object.gmaps4rails_description.nil? ? "" : object.gmaps4rails_description
41
+ lat = object.gmaps4rails_latitude.nil? ? "" : object.gmaps4rails_latitude
42
+ long = object.gmaps4rails_longitude.nil? ? "" : object.gmaps4rails_longitude
43
+
44
+ xml.description desc
45
+ xml.Point do
46
+ str = long + "," + lat + ",0"
47
+ xml.coordinates(str)
48
+ end
49
+ end #placemark
50
+ end
51
+ end
52
+
53
+ end #Document
54
+ end #kml
data/config/routes.rb ADDED
@@ -0,0 +1,12 @@
1
+ Rails.application.routes.draw do |map|
2
+
3
+ mount_at = Gmaps4rails::Engine.config.mount_at
4
+
5
+ match mount_at => 'gmaps4rails/gmaps#index'
6
+
7
+ map.resources :gmaps, :only => [ :index, :show ],
8
+ :controller => "gmaps4rails/gmaps",
9
+ :path_prefix => mount_at#,
10
+ #:name_prefix => "gmaps4rails_"
11
+
12
+ end
@@ -0,0 +1,68 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+
4
+ module Gmaps4rails
5
+ module ActsAsGmappable
6
+
7
+ module Base
8
+ def self.included(klass)
9
+ klass.class_eval do
10
+ extend Config
11
+ end
12
+ end
13
+
14
+ module Config
15
+ def acts_as_gmappable options = {}
16
+ before_save :get_coordinates
17
+
18
+ #attr_accessor :goptions
19
+
20
+ #write_inheritable_attribute(:goptions, {}) if goptions.nil?
21
+ #
22
+ # def goptions
23
+ # read_inheritable_attribute(:goptions)
24
+ # end
25
+ # This is where arbitrary code goes that you want to
26
+ # add to the class that declared "acts_as_widget"
27
+
28
+ #has_many :widgets, :class_name => 'Gmaps4rails::Widget'
29
+
30
+ def self.is_gmappable?
31
+ true
32
+ end
33
+
34
+ include Gmaps4rails::ActsAsGmappable::Base::InstanceMethods
35
+ end
36
+ end
37
+
38
+ module InstanceMethods
39
+
40
+ def get_coordinates
41
+ if self.adress.nil? || self.adress == ""
42
+ self.gmaps = false
43
+ else
44
+ geocoder = "http://maps.google.com/maps/geo?q="
45
+ output = "&output=csv"
46
+ #send request to the google api to get the lat/lng
47
+ request = geocoder + self.adress + output
48
+ url = URI.escape(request)
49
+ resp = Net::HTTP.get_response(URI.parse(url))
50
+ #parse result if result received properly
51
+ if resp.inspect.include?('HTTPOK 200 OK')
52
+ fields = resp.body.split(',')
53
+ self.latitude = fields[2]
54
+ self.longitude = fields[3]
55
+ #saves a boolean to remind the status
56
+ self.gmaps = true
57
+ else
58
+ self.gmaps = false
59
+ end
60
+ end
61
+ return true
62
+ end
63
+ end # InstanceMethods
64
+ end
65
+ end
66
+ end
67
+
68
+ ::ActiveRecord::Base.send :include, Gmaps4rails::ActsAsGmappable::Base
@@ -0,0 +1,13 @@
1
+ module ApplicationHelper
2
+ def gmaps4rails_filters_display(model)
3
+ if model.constantize.respond_to?("gmaps4rails_filters")
4
+ display = '<form name="gmaps4rails_form">'
5
+ display += '<select name="gmaps4rails_list" onChange="gmaps4rails_resfreshmap()">'
6
+ model.constantize.gmaps4rails_filters.each do |filter_hash|
7
+ display += '<option value="' + filter_hash["filter"] + '+' + filter_hash["options"] +'">' + filter_hash["display"]
8
+ end
9
+ display += '</select></form>'
10
+ end
11
+ display
12
+ end
13
+ end
data/lib/engine.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'gmaps4rails'
2
+ require 'rails'
3
+ require 'action_controller'
4
+ require 'application_helper'
5
+
6
+ module Gmaps4rails
7
+ class Engine < Rails::Engine
8
+
9
+ # Config defaults
10
+ config.widget_factory_name = "gmaps4rails"
11
+ config.mount_at = '/'
12
+
13
+ # Load rake tasks
14
+ rake_tasks do
15
+ load File.join(File.dirname(__FILE__), 'rails/railties/tasks.rake')
16
+ end
17
+
18
+ # Check the gem config
19
+ initializer "check config" do |app|
20
+
21
+ # make sure mount_at ends with trailing slash
22
+ config.mount_at += '/' unless config.mount_at.last == '/'
23
+ end
24
+
25
+ initializer "static assets" do |app|
26
+ app.middleware.use ::ActionDispatch::Static, "#{root}/public"
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,4 @@
1
+ module Gmaps4rails
2
+ require 'engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
3
+ require 'acts_as_gmappable/base'
4
+ end
@@ -0,0 +1,75 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+
4
+ class Gmaps4railsGenerator < Rails::Generators::Base
5
+ include Rails::Generators::Migration
6
+
7
+ def self.source_root
8
+ File.join(File.dirname(__FILE__), 'templates')
9
+ end
10
+
11
+ def self.next_migration_number(dirname) #:nodoc:
12
+ if ActiveRecord::Base.timestamped_migrations
13
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
14
+ else
15
+ "%.3d" % (current_migration_number(dirname) + 1)
16
+ end
17
+ end
18
+
19
+
20
+ # Every method that is declared below will be automatically executed when the generator is run
21
+
22
+ def create_migration_file
23
+ f = File.open File.join(File.dirname(__FILE__), 'templates', 'schema.rb')
24
+ schema = f.read; f.close
25
+
26
+ schema.gsub!(/ActiveRecord::Schema.*\n/, '')
27
+ schema.gsub!(/^end\n*$/, '')
28
+
29
+ f = File.open File.join(File.dirname(__FILE__), 'templates', 'migration.rb')
30
+ migration = f.read; f.close
31
+ migration.gsub!(/SCHEMA_AUTO_INSERTED_HERE/, schema)
32
+
33
+ tmp = File.open "tmp/~migration_ready.rb", "w"
34
+ tmp.write migration
35
+ tmp.close
36
+
37
+ migration_template '../../../tmp/~migration_ready.rb',
38
+ 'db/migrate/create_gmaps4rails_tables.rb'
39
+ remove_file 'tmp/~migration_ready.rb'
40
+ end
41
+
42
+ def copy_initializer_file
43
+ copy_file 'initializer.rb', 'config/initializers/gmaps4rails.rb'
44
+ end
45
+
46
+ def update_application_template
47
+ f = File.open "app/views/layouts/application.html.erb"
48
+ layout = f.read; f.close
49
+
50
+ if layout =~ /<%=[ ]+yield[ ]+%>/
51
+ print " \e[1m\e[34mquestion\e[0m Your layouts/application.html.erb layout currently has the line <%= yield %>. This gem needs to change this line to <%= content_for?(:content) ? yield(:content) : yield %> to support its nested layouts. This change should not affect any of your existing layouts or views. Is this okay? [y/n] "
52
+ begin
53
+ answer = gets.chomp
54
+ end while not answer =~ /[yn]/i
55
+
56
+ if answer =~ /y/i
57
+
58
+ layout.gsub!(/<%=[ ]+yield[ ]+%>/, '<%= content_for?(:content) ? yield(:content) : yield %>')
59
+
60
+ tmp = File.open "tmp/~application.html.erb", "w"
61
+ tmp.write layout; tmp.close
62
+
63
+ remove_file 'app/views/layouts/application.html.erb'
64
+ copy_file '../../../tmp/~application.html.erb',
65
+ 'app/views/layouts/application.html.erb'
66
+ remove_file 'tmp/~application.html.erb'
67
+ end
68
+ elsif layout =~ /<%=[ ]+content_for\?\(:content\) \? yield\(:content\) : yield[ ]+%>/
69
+ puts " \e[1m\e[33mskipping\e[0m layouts/application.html.erb modification is already done."
70
+ else
71
+ puts " \e[1m\e[31mconflict\e[0m The gem is confused by your layouts/application.html.erb. It does not contain the default line <%= yield %>, you may need to make manual changes to get this gem's nested layouts working. Visit ###### for details."
72
+ end
73
+ end
74
+
75
+ end
@@ -0,0 +1,8 @@
1
+ module Gmaps4rails
2
+ class Engine < Rails::Engine
3
+
4
+ config.mount_at = '/gmaps4rails'
5
+ config.widget_factory_name = 'Factory Name'
6
+
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ class CreateGmaps4railsTables < ActiveRecord::Migration
2
+ def self.up
3
+ SCHEMA_AUTO_INSERTED_HERE
4
+ end
5
+
6
+ def self.down
7
+ drop_table :gmaps4rails_widgets
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ ActiveRecord::Schema.define(:version => 0) do
2
+
3
+ create_table :gmaps4rails_widgets, :force => true do |t|
4
+ t.string :title
5
+ t.datetime :created_at
6
+ t.datetime :updated_at
7
+ end
8
+
9
+ add_index :gmaps4rails_widgets, [:title]
10
+
11
+ end
@@ -0,0 +1,8 @@
1
+ namespace :gmaps4rails do
2
+
3
+ desc "example gem rake task"
4
+ task :report => :environment do
5
+ puts "you just ran the example gem rake task"
6
+ end
7
+
8
+ end
@@ -0,0 +1,49 @@
1
+ var gmaps4rails_map;
2
+ var gmaps4rails_Options;
3
+ var gmaps4rails_ctaLayer;
4
+ var gmaps4rails_model;
5
+
6
+ function gmaps4rails_init(model) {
7
+ gmaps4rails_model = model;
8
+ var myLatLng = new google.maps.LatLng(0,0);
9
+ gmaps4rails_Options = {
10
+ zoom: 2,
11
+ center: myLatLng,
12
+ mapTypeId: google.maps.MapTypeId.ROADMAP
13
+ }
14
+ gmaps4rails_map = new google.maps.Map(document.getElementById("gmaps4rails_canvas"), gmaps4rails_Options);
15
+ create_map();
16
+ }
17
+
18
+ function create_map(filter_value) {
19
+ var date = new Date();
20
+ //adding the date (which is a unique parameter, enables to bypass google map's cache on google server)
21
+ var request = 'http://furious-robot-66.heroku.com/gmaps.xml?model=' + gmaps4rails_model + '&time=' + date.getTime();
22
+ if (!(filter_value == null))
23
+ {
24
+ split_filter_value = filter_value.split('+');
25
+ if (!(split_filter_value[0] == null))
26
+ {
27
+ request += '&filter=' + split_filter_value[0];
28
+ }
29
+ if (!(split_filter_value[1] == null))
30
+ {
31
+ request += '&options=' + split_filter_value[1];
32
+ }
33
+ }
34
+ alert(request);
35
+ gmaps4rails_ctaLayer = new google.maps.KmlLayer(request);
36
+ gmaps4rails_ctaLayer.setMap(gmaps4rails_map);
37
+ }
38
+
39
+ function gmaps4rails_raz(){
40
+ gmaps4rails_map = new google.maps.Map(document.getElementById("gmaps4rails_canvas"), gmaps4rails_myOptions);
41
+ }
42
+
43
+ function gmaps4rails_resfreshmap()
44
+ {
45
+ gmaps4rails_raz();
46
+ var index = document.gmaps4rails_form.gmaps4rails_list.selectedIndex;
47
+ var filter_value = document.gmaps4rails_form.gmaps4rails_list.options[index].value;
48
+ create_map(filter_value);
49
+ }
@@ -0,0 +1,56 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+
3
+ require 'test/unit'
4
+ require 'rubygems'
5
+ require 'yaml'
6
+ require 'active_record'
7
+ require 'mysql'
8
+
9
+ require 'app/models/gmaps4rails/widget.rb'
10
+
11
+ def gmaps4rails_widget( fixture_name )
12
+ id = @@fixtures['gmaps4rails_widget'][ fixture_name.to_s ][ 'id' ]
13
+ gmaps4rails::Widget.find( id )
14
+ end
15
+
16
+ def load_schema
17
+ config = YAML::load( IO.read( File.dirname(__FILE__) + '/database.yml') )
18
+
19
+ # Manually initialize the database
20
+ conn = Mysql.real_connect( config['mysql']['host'], config['mysql']['username'], config['mysql']['password'] )
21
+ conn.query( "CREATE DATABASE IF NOT EXISTS #{config['mysql']['database']}" )
22
+
23
+ ActiveRecord::Base.establish_connection( config['mysql'] )
24
+ ActiveRecord::Base.connection()
25
+
26
+ load(File.dirname(__FILE__) + "/../" +
27
+ "lib/rails/generators/gmaps4rails/templates/schema.rb")
28
+
29
+ @@fixtures = {}
30
+
31
+ load_fixture( 'gmaps4rails_widget' )
32
+ end
33
+
34
+ def load_fixture( table )
35
+ @@fixtures[ table ] = {}
36
+ fixture = YAML::load( IO.read( File.dirname(__FILE__) + "/fixtures/#{table}.yml") )
37
+ @@fixtures[ table ] = fixture
38
+
39
+ klass = class_eval table.titleize.gsub(/ /, '::')
40
+
41
+ fixture.each do |record_name, record|
42
+ record.each do |column, value|
43
+ if ( match = column.match(/(.*)_id/) )
44
+ fixture_reference = "gmaps4rails_" + match[1].pluralize
45
+ if value.is_a? Symbol
46
+ r = class_eval "#{fixture_reference}( '#{value}' )"
47
+ record[ column ] = r.id
48
+ end
49
+ end
50
+ end
51
+
52
+ r = klass.create( record )
53
+ @@fixtures[ table ][ record_name ][ 'id' ] = r.id
54
+ end
55
+
56
+ end
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+
3
+ class WidgetTest < Test::Unit::TestCase
4
+ load_schema
5
+
6
+ def test_fixtures_are_working
7
+ assert_equal gmaps4rails_widget(:first).title, "This is the title"
8
+ end
9
+
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gmaps4rails
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 0
10
+ version: 0.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Benjamin Roth
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-10 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Enable easy display of items (taken from a model) on a Google Map. Uses Javascript API V3.
23
+ email: apnea.diving.deep@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README.rdoc
30
+ files:
31
+ - app/controllers/gmaps4rails/gmaps_controller.rb
32
+ - app/helpers/application_helper.rb
33
+ - app/helpers/gmaps4rails/Gmaps_helper.rb
34
+ - app/models/gmaps4rails/gmaps.rb
35
+ - app/views/gmaps4rails/_map.html.erb
36
+ - app/views/gmaps4rails/gmaps/index.html.erb
37
+ - app/views/gmaps4rails/gmaps/index.xml.builder
38
+ - config/routes.rb
39
+ - lib/acts_as_gmappable/base.rb
40
+ - lib/application_helper.rb
41
+ - lib/engine.rb
42
+ - lib/gmaps4rails.rb
43
+ - lib/rails/generators/gmaps4rails/gmaps4rails_generator.rb
44
+ - lib/rails/generators/gmaps4rails/templates/initializer.rb
45
+ - lib/rails/generators/gmaps4rails/templates/migration.rb
46
+ - lib/rails/generators/gmaps4rails/templates/schema.rb
47
+ - lib/rails/railties/tasks.rake
48
+ - public/javascripts/gmaps4rails.js
49
+ - README.rdoc
50
+ - test/test_helper.rb
51
+ - test/unit/gmaps4rails_widget_test.rb
52
+ has_rdoc: true
53
+ homepage: http://github.com/apneadiving/test-for-maps
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options:
58
+ - --charset=UTF-8
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ hash: 3
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ requirements: []
80
+
81
+ rubyforge_project:
82
+ rubygems_version: 1.3.7
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Enable easy display of items (taken from a model) on a Google Map. Uses Javascript API V3.
86
+ test_files:
87
+ - test/test_helper.rb
88
+ - test/unit/gmaps4rails_widget_test.rb