maptastic 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
@@ -0,0 +1,106 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ maptastic (0.1.0)
5
+ rails (>= 3.0.0.rc)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ abstract (1.0.0)
11
+ actionmailer (3.0.0.rc)
12
+ actionpack (= 3.0.0.rc)
13
+ mail (~> 2.2.5)
14
+ actionpack (3.0.0.rc)
15
+ activemodel (= 3.0.0.rc)
16
+ activesupport (= 3.0.0.rc)
17
+ builder (~> 2.1.2)
18
+ erubis (~> 2.6.6)
19
+ i18n (~> 0.4.1)
20
+ rack (~> 1.2.1)
21
+ rack-mount (~> 0.6.9)
22
+ rack-test (~> 0.5.4)
23
+ tzinfo (~> 0.3.22)
24
+ activemodel (3.0.0.rc)
25
+ activesupport (= 3.0.0.rc)
26
+ builder (~> 2.1.2)
27
+ i18n (~> 0.4.1)
28
+ activerecord (3.0.0.rc)
29
+ activemodel (= 3.0.0.rc)
30
+ activesupport (= 3.0.0.rc)
31
+ arel (~> 0.4.0)
32
+ tzinfo (~> 0.3.22)
33
+ activeresource (3.0.0.rc)
34
+ activemodel (= 3.0.0.rc)
35
+ activesupport (= 3.0.0.rc)
36
+ activesupport (3.0.0.rc)
37
+ arel (0.4.0)
38
+ activesupport (>= 3.0.0.beta)
39
+ autotest (4.3.2)
40
+ builder (2.1.2)
41
+ diff-lcs (1.1.2)
42
+ erubis (2.6.6)
43
+ abstract (>= 1.0.0)
44
+ haml (2.2.24)
45
+ hanna (0.1.12)
46
+ haml (~> 2.2.8)
47
+ rake (~> 0.8.2)
48
+ rdoc (~> 2.3.0)
49
+ i18n (0.4.1)
50
+ mail (2.2.5)
51
+ activesupport (>= 2.3.6)
52
+ mime-types
53
+ treetop (>= 1.4.5)
54
+ mime-types (1.16)
55
+ nokogiri (1.4.2)
56
+ polyglot (0.3.1)
57
+ rack (1.2.1)
58
+ rack-mount (0.6.9)
59
+ rack (>= 1.0.0)
60
+ rack-test (0.5.4)
61
+ rack (>= 1.0)
62
+ rails (3.0.0.rc)
63
+ actionmailer (= 3.0.0.rc)
64
+ actionpack (= 3.0.0.rc)
65
+ activerecord (= 3.0.0.rc)
66
+ activeresource (= 3.0.0.rc)
67
+ activesupport (= 3.0.0.rc)
68
+ bundler (>= 1.0.0.rc.1)
69
+ railties (= 3.0.0.rc)
70
+ railties (3.0.0.rc)
71
+ actionpack (= 3.0.0.rc)
72
+ activesupport (= 3.0.0.rc)
73
+ rake (>= 0.8.3)
74
+ thor (~> 0.14.0)
75
+ rake (0.8.7)
76
+ rdoc (2.3.0)
77
+ rspec (2.0.0.beta.19)
78
+ rspec-core (= 2.0.0.beta.19)
79
+ rspec-expectations (= 2.0.0.beta.19)
80
+ rspec-mocks (= 2.0.0.beta.19)
81
+ rspec-core (2.0.0.beta.19)
82
+ rspec-expectations (2.0.0.beta.19)
83
+ diff-lcs (>= 1.1.2)
84
+ rspec-mocks (2.0.0.beta.19)
85
+ rspec-rails (2.0.0.beta.19)
86
+ rspec (= 2.0.0.beta.19)
87
+ webrat (>= 0.7.2.beta.1)
88
+ thor (0.14.0)
89
+ treetop (1.4.8)
90
+ polyglot (>= 0.3.1)
91
+ tzinfo (0.3.22)
92
+ webrat (0.7.2.beta.1)
93
+ nokogiri (>= 1.2.0)
94
+ rack (>= 1.0)
95
+ rack-test (>= 0.5.3)
96
+
97
+ PLATFORMS
98
+ ruby
99
+
100
+ DEPENDENCIES
101
+ autotest (>= 4.3.2)
102
+ hanna (>= 0.1.12)
103
+ maptastic!
104
+ rails (>= 3.0.0.rc)
105
+ rspec (>= 2.0.0.beta.18)
106
+ rspec-rails (>= 2.0.0.beta.18)
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Benedikt Deicke
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,62 @@
1
+ = maptastic
2
+
3
+ The maptastic plugin for Ruby on Rails provides simple and unobtrusive helper methods and javascript libraries to integrate maps in web applications.
4
+
5
+ == Requirements
6
+
7
+ Maptastic currently only works with Google Maps and Prototype. This might change in the future but for now that's how it is.
8
+
9
+ == Install
10
+
11
+ To install the maptastic gem, simply add it to your Gemfile:
12
+
13
+ gem 'maptastic'
14
+
15
+ In order to get the latest development version of maptastic:
16
+
17
+ gem 'maptastic', :git => 'git://github.com/benedikt/maptastic.git'
18
+
19
+ and run
20
+
21
+ bundle install
22
+
23
+ Afterwards you can run the generator to get the necessary files installed into your application
24
+
25
+ rails generate maptastic:install
26
+
27
+ To include the required javascripts put these two lines in your application.html.erb
28
+
29
+ <%= maptastic_provider_tag %>
30
+ <%= javascript_include_tag 'maptastic' %>
31
+
32
+ To finalize the installation please set your Google Maps API key in <tt>config/initializers/maptastic.rb</tt>
33
+
34
+ == Configuration
35
+
36
+ To configure maptastic to your needs edit the <tt>config/initializers/maptastic.rb</tt> file.
37
+
38
+ == Usage
39
+
40
+ Read the API documentation at http://rdoc.info/projects/benedikt/maptastic
41
+
42
+ Examples (without markers):
43
+
44
+ <%= maptastic :center => [37.4419, -122.1419] %>
45
+ <%= maptastic :center => @poi %> # @poi.latitude and @poi.longitude are used
46
+
47
+ Examples (with markers):
48
+
49
+ <%= maptastic @poi %> # Simple marker without info window
50
+ <%= maptastic @pois do |poi| %>
51
+ Generates a marker with info window (bubble). Uses @poi.latitude and @poi.longitude
52
+ to position the marker.
53
+ <%= poi.name %>
54
+ <% end %>
55
+
56
+ Available options:
57
+
58
+ <%= maptastic :center => [37.4419, -122.1419], :zoom => 10; :controls => true %>
59
+
60
+ == Copyright
61
+
62
+ Copyright (c) 2010 Benedikt Deicke. See LICENSE for details.
@@ -0,0 +1,33 @@
1
+ require 'rspec/core'
2
+ require 'rspec/core/rake_task'
3
+ require 'hanna/rdoctask'
4
+
5
+ spec = Gem::Specification.load("maptastic.gemspec")
6
+
7
+ RSpec::Core::RakeTask.new
8
+ task :default => :spec
9
+
10
+ Rake::RDocTask.new do |rdoc|
11
+ rdoc.rdoc_dir = 'doc'
12
+ rdoc.title = "#{spec.name} #{spec.version}"
13
+ rdoc.options += spec.rdoc_options
14
+ rdoc.rdoc_files.include(spec.extra_rdoc_files)
15
+ rdoc.rdoc_files.include('lib/**/*.rb')
16
+ end
17
+
18
+ desc "Generates a sandbox Rails app for testing"
19
+ namespace :spec do
20
+ task "sandbox" do
21
+ system "mkdir -p tmp/ && bundle exec rails new tmp/sandbox --skip-gemfile"
22
+ end
23
+ end
24
+
25
+ desc "Build the .gem file"
26
+ task :build do
27
+ system "gem build #{spec.name}.gemspec"
28
+ end
29
+
30
+ desc "Push the .gem file to rubygems.org"
31
+ task :release => :build do
32
+ system "gem push #{spec.name}-#{spec.version}.gem"
33
+ end
@@ -0,0 +1,4 @@
1
+ module Maptastic
2
+ module Generators # :nodoc:
3
+ end
4
+ end
@@ -0,0 +1,21 @@
1
+ module Maptastic
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base #:nodoc:
4
+ desc "Creates a Maptastic initializer and copies the required javascript files."
5
+
6
+ def self.source_root
7
+ File.expand_path("../../templates", __FILE__)
8
+ end
9
+
10
+ def copy_initializer
11
+ template "maptastic.rb", "config/initializers/maptastic.rb"
12
+ end
13
+
14
+ def copy_javascripts
15
+ copy_file "maptastic.js", "public/javascripts/maptastic.js"
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,97 @@
1
+ var Maptastic = {};
2
+
3
+ Object.extend(Maptastic, {
4
+
5
+ setup: function() {
6
+ $$("div[data-map=true]").each(function(element) { new Maptastic.Map(element); });
7
+ },
8
+
9
+ toLatLng: function(string) {
10
+ var coordinates = string.split(" ");
11
+ return new google.maps.LatLng(coordinates[0], coordinates[1]);
12
+ }
13
+
14
+ });
15
+
16
+ Maptastic.Map = Class.create({
17
+
18
+ initialize: function(element) {
19
+ this.element = $(element);
20
+ this.collectMarkers();
21
+
22
+ this.mapOptions = {
23
+ mapTypeId: google.maps.MapTypeId.ROADMAP
24
+ };
25
+ this.setupMap();
26
+
27
+ this.map = new google.maps.Map(this.element, this.mapOptions);
28
+
29
+ this.setupMarkers();
30
+ },
31
+
32
+ setupMap: function() {
33
+ with(this) {
34
+ setupCenter();
35
+ setupZoom();
36
+ setupControls();
37
+ }
38
+ },
39
+
40
+ collectMarkers: function() {
41
+ this.markers = this.element.select("div[data-map-marker=true]");
42
+ },
43
+
44
+ setupCenter: function() {
45
+ with(this) {
46
+ mapOptions['center'] = Maptastic.toLatLng(element.readAttribute("data-map-center"));
47
+ }
48
+ },
49
+
50
+ setupZoom: function() {
51
+ with(this) {
52
+ if(element.hasAttribute("data-map-zoom")) {
53
+ mapOptions['zoom'] = parseInt(element.readAttribute("data-map-zoom"));
54
+ }
55
+ }
56
+ },
57
+
58
+ setupControls: function() {
59
+ with(this) {
60
+ mapOptions['disableDefaultUI'] = !element.hasAttribute("data-map-controls")
61
+
62
+ if(element.readAttribute("data-map-controls-dragging") == "false") {
63
+ mapOptions['draggable'] = false;
64
+ }
65
+
66
+ if(element.readAttribute("data-map-controls-zooming") == "false") {
67
+ mapOptions['scrollwheel'] = false;
68
+ mapOptions['disableDoubleClickZoom'] = false;
69
+ }
70
+ }
71
+ },
72
+
73
+ setupMarkers: function() {
74
+ this.markers.each(function(element) {
75
+
76
+ var marker = new google.maps.Marker({
77
+ position: Maptastic.toLatLng(element.readAttribute("data-map-position")),
78
+ map: this.map,
79
+ title: "Hello World!"
80
+ });
81
+
82
+ if(!element.empty()) {
83
+ var infoWindow = new google.maps.InfoWindow({
84
+ content: element.innerHTML
85
+ });
86
+
87
+ google.maps.event.addListener(marker, 'click', function() {
88
+ infoWindow.open(this.map, marker);
89
+ }.bind(this));
90
+ }
91
+
92
+ }.bind(this));
93
+ }
94
+
95
+ });
96
+
97
+ document.observe("dom:loaded", function() { Maptastic.setup(); });
@@ -0,0 +1,29 @@
1
+ Maptastic.configure do |config|
2
+ # Set this to your Google Maps API Key
3
+ config.api_key = "PUT YOUR API KEY HERE"
4
+
5
+ # Attribute to use to get the longitude of an object
6
+ # Default: :longitude
7
+ # config.longitude_attribute = :lng
8
+
9
+ # Attribute to use to get the latitude of an object
10
+ # Default :latitude
11
+ # config.latitude_attribute = :lat
12
+
13
+ # Overrides the locale used to load the Google Maps API
14
+ # Default: Whatever defined as the current I18n.locale
15
+ # config.locale = :en
16
+
17
+ # Sets the default region behavior
18
+ # Default: Autodetected by Google Maps
19
+ # config.region = 'GB'
20
+
21
+ # Sets the default zoom level for maps
22
+ # Default: 10
23
+ # config.default_zoom_level = 10
24
+
25
+ # Load the API with sensor (gps device) support
26
+ # Default: nil
27
+ # config.sensor = false
28
+ end
29
+
@@ -0,0 +1,18 @@
1
+ module Maptastic
2
+ module Generators
3
+ class UpdateGenerator < Rails::Generators::Base #:nodoc:
4
+ desc "Updates the required javascript files."
5
+
6
+ def self.source_root
7
+ File.expand_path("../../templates", __FILE__)
8
+ end
9
+
10
+ def copy_javascripts
11
+ remove_file "public/javascripts/maptastic.js"
12
+ copy_file "maptastic.js", "public/javascripts/maptastic.js"
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,61 @@
1
+ require 'maptastic/railtie'
2
+
3
+ module Maptastic
4
+
5
+ ##
6
+ # :singleton-method: api_key
7
+ # Stores the application's Google Maps API key.
8
+ mattr_accessor :api_key
9
+ @@api_key = ""
10
+
11
+ ##
12
+ # :singleton-method: longitude_attribute
13
+ # Gets the attribute name used to get the longitude of an object
14
+ mattr_accessor :longitude_attribute
15
+ @@longitude_attribute = :longitude
16
+
17
+ ##
18
+ # :singleton-method: latitude_attribute
19
+ # Gets the attribute name used to get the latitude of an object
20
+ mattr_accessor :latitude_attribute
21
+ @@latitude_attribute = :latitude
22
+
23
+ ##
24
+ # :singleton-method: locale
25
+ # Gets the override locale used to load the Google Maps API
26
+ mattr_accessor :locale
27
+ @@locale = nil
28
+
29
+ ##
30
+ # :singleton-method: region
31
+ # Gets the defined region
32
+ mattr_accessor :region
33
+ @@region = nil
34
+
35
+
36
+ ##
37
+ # :singleton-method: default_zoom_level
38
+ # Gets the default zoom level for maps
39
+ mattr_accessor :default_zoom_level
40
+ @@default_zoom_level = 10
41
+
42
+ ##
43
+ # :singleton-method: sensor
44
+ # Gets the sensor option (load the api with gps device support)
45
+ # Default: nil
46
+ mattr_accessor :sensor
47
+ @@sensor = nil
48
+
49
+ ##
50
+ # Configure maptastic
51
+ #
52
+ # Example:
53
+ #
54
+ # Maptastic.configure do |config|
55
+ # config.locale = :de
56
+ # end
57
+ def self.configure
58
+ yield self
59
+ end
60
+
61
+ end
@@ -0,0 +1,15 @@
1
+ module Maptastic
2
+
3
+ class Railtie < Rails::Railtie # :nodoc:
4
+ config.maptastic = Maptastic
5
+
6
+ initializer "maptastic.action_view" do |app|
7
+ if defined? ::ActionView
8
+ require 'maptastic/view_helpers/action_view'
9
+ ActionView::Base.send(:include, Maptastic::ViewHelpers::ActionView)
10
+ end
11
+ end
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,3 @@
1
+ module Maptastic
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,4 @@
1
+ module Maptastic
2
+ module ViewHelpers
3
+ end
4
+ end
@@ -0,0 +1,63 @@
1
+ module Maptastic
2
+ module ViewHelpers
3
+ module ActionView
4
+
5
+ ##
6
+ # Generates a simple map.
7
+ #
8
+ # Available options:
9
+ #
10
+ # *
11
+ #
12
+ def maptastic(*args, &block)
13
+ options = args.extract_options!
14
+
15
+ markers = (args.first.respond_to? :each) ? args.first : [args.first]
16
+
17
+ options["data-map"] = true
18
+ options["data-map-zoom"] = options.delete(:zoom) || Maptastic.default_zoom_level
19
+ options["data-map-controls"] = options.delete(:controls)
20
+ options["data-map-controls-dragging"] = options.delete(:dragging)
21
+ options["data-map-controls-zooming"] = options.delete(:zooming)
22
+
23
+ options["data-map-center"] = [:client, :marker].include?(options[:center]) ?
24
+ options.delete(:center) : coordinates_for(options.delete(:center) || markers.first)
25
+
26
+
27
+ content_tag(:div, marker_html_for(markers, &block), options)
28
+ end
29
+
30
+ def maptastic_provider_tag
31
+ provider_url = "http://maps.google.com/maps/api/js?v=3".tap do |u|
32
+ u << "&sensor=" + (Maptastic.sensor ? "true" : "false")
33
+ u << "&language=" + (Maptastic.locale || I18n.locale).to_s if Maptastic.locale || I18n.locale
34
+ u << "&region=" + Maptastic.region if Maptastic.region
35
+ end
36
+ javascript_include_tag provider_url
37
+ end
38
+
39
+ private
40
+
41
+ def coordinates_for(point)
42
+ if point.respond_to?(Maptastic.latitude_attribute) && point.respond_to?(Maptastic.longitude_attribute)
43
+ lat, lng = point.send(Maptastic.latitude_attribute), point.send(Maptastic.longitude_attribute)
44
+ elsif point.kind_of?(Array) && point.size >= 2
45
+ lat, lng = point[0], point[1]
46
+ else
47
+ return nil
48
+ end
49
+ return "#{lat} #{lng}"
50
+ end
51
+
52
+ def marker_html_for(markers, &block)
53
+ return "".html_safe.tap do |html|
54
+ markers.each do |marker|
55
+ options = { "data-map-marker" => true, "data-map-position" => coordinates_for(marker) }
56
+ html << content_tag(:div, (block_given? ? capture(marker, &block) : ""), options)
57
+ end
58
+ end
59
+ end
60
+
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,144 @@
1
+ require 'spec_helper'
2
+ require 'maptastic/view_helpers/action_view'
3
+
4
+ describe Maptastic::ViewHelpers::ActionView do
5
+
6
+ describe "#maptastic_provider_tag" do
7
+
8
+ it "should exist" do
9
+ helper.should respond_to :maptastic_provider_tag
10
+ end
11
+
12
+ it "should return a script tag" do
13
+ helper.maptastic_provider_tag.should have_selector("script[type='text/javascript']")
14
+ end
15
+
16
+ it "should use Google Maps API v3" do
17
+ helper.maptastic_provider_tag.should match /v=3/
18
+ end
19
+
20
+ it "should use the current I18n.locale" do
21
+ I18n.stub(:locale => :de)
22
+ helper.maptastic_provider_tag.should match /language=de/
23
+ end
24
+
25
+ it "should use the locale defined in the config when available" do
26
+ I18n.stub(:locale => :en)
27
+ Maptastic.stub(:locale => :de)
28
+ helper.maptastic_provider_tag.should match /language=de/
29
+ end
30
+
31
+ it "should set the region when defined" do
32
+ Maptastic.stub(:region => 'GB')
33
+ helper.maptastic_provider_tag.should match /region=GB/
34
+ end
35
+
36
+ it "should use the sensor parameter if set to true" do
37
+ Maptastic.stub(:sensor => true)
38
+ helper.maptastic_provider_tag.should match /sensor=true/
39
+ end
40
+
41
+ it "should use the sensor parameter set to false if not set to true" do
42
+ Maptastic.stub(:sensor => nil)
43
+ helper.maptastic_provider_tag.should match /sensor=false/
44
+ end
45
+ end
46
+
47
+ describe "#maptastic" do
48
+
49
+ it "should have a data-map=true attribute" do
50
+ helper.maptastic.should have_selector("div[data-map=true]")
51
+ end
52
+
53
+ it "should have a data-map-zoom attribute set to the default defined in the config" do
54
+ Maptastic.stub(:default_zoom_level => 5)
55
+ helper.maptastic.should have_selector("div[data-map-zoom='5']")
56
+ end
57
+
58
+ { :controls => "data-map-controls",
59
+ :dragging => "data-map-controls-dragging",
60
+ :zooming => "data-map-controls-zooming" }.each_pair do |option, attribute|
61
+ it "should map option #{option} to attribute #{attribute} " do
62
+ helper.maptastic(option => true).should have_selector("div[#{attribute}=true]")
63
+ end
64
+ end
65
+
66
+ it "should have a data-map-zoom attribute set to the given value" do
67
+ helper.maptastic(:zoom => 7).should have_selector("div[data-map-zoom='7']")
68
+ end
69
+
70
+ it "should have data-map-controls=true if specified" do
71
+ helper.maptastic(:controls => true).should have_selector("div[data-map-controls=true]")
72
+ end
73
+
74
+ it "should not have data-map-controls=true if not specified" do
75
+ helper.maptastic.should_not have_selector("div[data-map-controls]")
76
+ end
77
+
78
+ it "should set data-map-center to the coordinates given as array" do
79
+ helper.maptastic(:center => [123, 456]).should have_selector("div[data-map-center='123 456']")
80
+ end
81
+
82
+ it "should set data-map-center to the coordinates given as an object" do
83
+ point = mock(:latitude => 123, :longitude => 456)
84
+ helper.maptastic(:center => point).should have_selector("div[data-map-center='123 456']")
85
+ end
86
+
87
+ it "should use the attributes given in the config on an object" do
88
+ Maptastic.stub(:latitude_attribute => :lat, :longitude_attribute => :lng)
89
+ point = mock(:lat => 123, :lng => 456)
90
+ helper.maptastic(:center => point).should have_selector("div[data-map-center='123 456']")
91
+ end
92
+
93
+ it "should not have data-map-center if not specified" do
94
+ helper.maptastic.should_not have_selector("div[data-map-center]")
95
+ end
96
+
97
+ context "with markers" do
98
+
99
+ let(:point) { mock(:latitude => 123, :longitude => 456) }
100
+ let(:points) { [mock(:latitude => 123, :longitude => 456), mock(:latitude => 654, :longitude => 321)] }
101
+
102
+ it "should use the given point as marker" do
103
+ helper.maptastic(point).should have_selector("div[data-map-marker=true][data-map-position='123 456']")
104
+ end
105
+
106
+ it "should use the given point as center" do
107
+ helper.maptastic(point).should have_selector("div[data-map-center='123 456']")
108
+ end
109
+
110
+ it "should use the first point as center" do
111
+ helper.maptastic(points).should have_selector("div[data-map-center='123 456']")
112
+ end
113
+
114
+ it "should use the center option when given" do
115
+ helper.maptastic(point, :center => [654, 321]).should have_selector("div[data-map-center='654 321']")
116
+ end
117
+
118
+ it "should accept :client as center option" do
119
+ helper.maptastic(point, :center => :client).should have_selector("div[data-map-center=client]")
120
+ end
121
+
122
+ it "should accept :marker as center option" do
123
+ helper.maptastic(point, :center => :marker).should have_selector("div[data-map-center=marker]")
124
+ end
125
+
126
+ it "should use all points in enumerable as markers" do
127
+ output = helper.maptastic(points)
128
+ output.should have_selector("div[data-map-marker=true][data-map-position='123 456']")
129
+ output.should have_selector("div[data-map-marker=true][data-map-position='654 321']")
130
+ end
131
+
132
+ it "should render the given block for each marker" do
133
+ output = helper.maptastic(points) do |point|
134
+ "--#{point.latitude}-#{point.longitude}--"
135
+ end
136
+ output.should contain("--123-456--")
137
+ output.should contain("--654-321--")
138
+ end
139
+
140
+ end
141
+
142
+ end
143
+
144
+ end
@@ -0,0 +1,30 @@
1
+ # This file is copied to ~/spec when you run 'ruby script/generate rspec'
2
+ # from the project root directory.
3
+ ENV["RAILS_ENV"] ||= 'test'
4
+
5
+ require 'rubygems'
6
+ require 'rails/all'
7
+ require 'maptastic'
8
+
9
+ require File.dirname(__FILE__) + "/../tmp/sandbox/config/environment"
10
+
11
+ require 'rspec/rails'
12
+
13
+ # Requires supporting files with custom matchers and macros, etc,
14
+ # in ./support/ and its subdirectories.
15
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
16
+
17
+ Rspec.configure do |config|
18
+ # == Mock Framework
19
+ #
20
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
21
+ #
22
+ # config.mock_with :mocha
23
+ # config.mock_with :flexmock
24
+ # config.mock_with :rr
25
+ config.mock_with :rspec
26
+
27
+ # If you'd prefer not to run each of your examples within a transaction,
28
+ # uncomment the following line.
29
+ # config.use_transactional_examples false
30
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: maptastic
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Benedikt Deicke
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-09 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rails
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 7712042
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 0
34
+ - rc
35
+ version: 3.0.0.rc
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: rspec
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 62196423
47
+ segments:
48
+ - 2
49
+ - 0
50
+ - 0
51
+ - beta
52
+ - 18
53
+ version: 2.0.0.beta.18
54
+ type: :development
55
+ version_requirements: *id002
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec-rails
58
+ prerelease: false
59
+ requirement: &id003 !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 62196423
65
+ segments:
66
+ - 2
67
+ - 0
68
+ - 0
69
+ - beta
70
+ - 18
71
+ version: 2.0.0.beta.18
72
+ type: :development
73
+ version_requirements: *id003
74
+ - !ruby/object:Gem::Dependency
75
+ name: autotest
76
+ prerelease: false
77
+ requirement: &id004 !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 55
83
+ segments:
84
+ - 4
85
+ - 3
86
+ - 2
87
+ version: 4.3.2
88
+ type: :development
89
+ version_requirements: *id004
90
+ - !ruby/object:Gem::Dependency
91
+ name: hanna
92
+ prerelease: false
93
+ requirement: &id005 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ - 1
102
+ - 12
103
+ version: 0.1.12
104
+ type: :development
105
+ version_requirements: *id005
106
+ description: The maptastic plugin for Ruby on Rails provides simple and unobtrusive helper methods and javascript libraries to integrate maps in web applications.
107
+ email:
108
+ - benedikt@synatic.net
109
+ executables: []
110
+
111
+ extensions: []
112
+
113
+ extra_rdoc_files:
114
+ - README.rdoc
115
+ - LICENSE
116
+ files:
117
+ - lib/generators/maptastic/install/install_generator.rb
118
+ - lib/generators/maptastic/templates/maptastic.js
119
+ - lib/generators/maptastic/templates/maptastic.rb
120
+ - lib/generators/maptastic/update/update_generator.rb
121
+ - lib/generators/maptastic.rb
122
+ - lib/maptastic/railtie.rb
123
+ - lib/maptastic/version.rb
124
+ - lib/maptastic/view_helpers/action_view.rb
125
+ - lib/maptastic/view_helpers.rb
126
+ - lib/maptastic.rb
127
+ - spec/helpers/action_view_spec.rb
128
+ - spec/spec_helper.rb
129
+ - LICENSE
130
+ - README.rdoc
131
+ - Rakefile
132
+ - Gemfile
133
+ - Gemfile.lock
134
+ - .rspec
135
+ has_rdoc: true
136
+ homepage: http://github.com/benedikt/maptastic
137
+ licenses: []
138
+
139
+ post_install_message:
140
+ rdoc_options:
141
+ - --main
142
+ - README.rdoc
143
+ - --charset=UTF-8
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ hash: 3
152
+ segments:
153
+ - 0
154
+ version: "0"
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ none: false
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ hash: 3
161
+ segments:
162
+ - 0
163
+ version: "0"
164
+ requirements: []
165
+
166
+ rubyforge_project:
167
+ rubygems_version: 1.3.7
168
+ signing_key:
169
+ specification_version: 3
170
+ summary: Simple and unobtrusive map integration plugin for Ruby on Rails
171
+ test_files: []
172
+