map_layers 0.0.3

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.
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "map_layers/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "map_layers"
7
+ s.version = MapLayers::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Luc Donnet", "Alban Peignier"]
10
+ s.email = ["luc.donnet@dryade.net", "alban.peignier@dryade.net"]
11
+ s.homepage = "http://github.com/ldonnet/map_layers"
12
+ s.summary = %q{library dedicated to generate OSM javascript}
13
+ s.description = %q{library dedicated to generate OSM javascript}
14
+
15
+ s.rubyforge_project = s.name
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ if ENV['RAILS_2']
23
+ s.add_development_dependency(%q<rails>, ["~> 2.3.8"])
24
+ else
25
+ s.add_development_dependency(%q<rails>, [">= 3.0.0"])
26
+ end
27
+ s.add_development_dependency(%q<rspec>, ["~> 2.0.0"])
28
+ s.add_development_dependency(%q<rspec-rails>, ["~> 2.0.0"])
29
+
30
+ s.add_development_dependency('rake')
31
+ s.add_development_dependency('autotest-rails')
32
+ s.add_development_dependency('autotest-notification')
33
+ end
data/rails/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "init"))
@@ -0,0 +1,140 @@
1
+ require 'spec_helper'
2
+
3
+ describe MapLayers::JsWrapper do
4
+
5
+ describe ".javascriptify_method" do
6
+ it "should return a js method" do
7
+ MapLayers::JsWrapper::javascriptify_method("add_overlay_to_hello").should == "addOverlayToHello"
8
+ end
9
+ end
10
+
11
+ describe ".javascriptify_variable" do
12
+
13
+ it "should return a javascript variable mapping object" do
14
+ map = MapLayers::Map.new("div")
15
+ MapLayers::JsWrapper::javascriptify_variable(map).should == map.to_javascript
16
+ end
17
+
18
+ it "should return a javascript numeric variable" do
19
+ MapLayers::JsWrapper::javascriptify_variable(123.4).should == "123.4"
20
+ end
21
+
22
+ it "should return a javascript array variable" do
23
+ map = MapLayers::Map.new("div")
24
+ MapLayers::JsWrapper::javascriptify_variable([123.4,map,[123.4,map]]).should == "[123.4,#{map.to_javascript},[123.4,#{map.to_javascript}]]"
25
+ end
26
+
27
+ it "should return a javascript hash variable" do
28
+ map = MapLayers::Map.new("div")
29
+ test_str = MapLayers::JsWrapper::javascriptify_variable("hello" => map, "chopotopoto" => [123.55,map])
30
+ test_str.should == "{hello : #{map.to_javascript},chopotopoto : [123.55,#{map.to_javascript}]}"
31
+ end
32
+ end
33
+
34
+ describe ".declare" do
35
+ it "should declare a latlng variable" do
36
+ point = OpenLayers::LonLat.new(123.4,123.6)
37
+ point.declare("point").should == "var point = new OpenLayers.LonLat(123.4,123.6);"
38
+ point.variable.should == "point"
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+
45
+ describe MapLayers::JsVar do
46
+
47
+ it "should test array indexing" do
48
+ obj = MapLayers::JsVar.new("obj")
49
+ obj[0].variable.should == "obj[0]"
50
+ end
51
+
52
+ end
53
+
54
+ describe MapLayers::JsGenerator do
55
+
56
+ it "should test js generator" do
57
+ @map = MapLayers::Map.new("map")
58
+ js = MapLayers::JsGenerator.new
59
+ js.assign("markers", OpenLayers::Layer::Markers.new('Markers'))
60
+ @markers = MapLayers::JsVar.new('markers')
61
+ js << @map.addLayer(@markers)
62
+ js.assign("size", OpenLayers::Size.new(10,17))
63
+ js.assign("offset", OpenLayers::Pixel.new(MapLayers::JsExpr.new("-(size.w/2), -size.h")))
64
+ js.assign("icon", OpenLayers::Icon.new('http://boston.openguides.org/markers/AQUA.png',:size,:offset))
65
+ js << @markers.add_marker(OpenLayers::Marker.new(OpenLayers::LonLat.new(0,0),:icon))
66
+ html =<<EOS
67
+ markers = new OpenLayers.Layer.Markers("Markers");
68
+ map.addLayer(markers);
69
+ size = new OpenLayers.Size(10,17);
70
+ offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
71
+ icon = new OpenLayers.Icon("http://boston.openguides.org/markers/AQUA.png",size,offset);
72
+ markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(0,0),icon));
73
+ EOS
74
+ js.to_s.should == html
75
+ end
76
+
77
+ it "should test google example" do
78
+ @map = MapLayers::Map.new("map") do |map, page|
79
+ page << map.add_layer(MapLayers::GOOGLE)
80
+ page << map.zoom_to_max_extent()
81
+ end
82
+ html =<<EOS
83
+ <script defer="defer" type="text/javascript">
84
+ var map;
85
+ map = new OpenLayers.Map('map', {theme : false});
86
+ map.addLayer(new OpenLayers.Layer.Google("Google Street"));
87
+ map.zoomToMaxExtent();
88
+ </script>
89
+ EOS
90
+ @map.to_html.should == html
91
+ end
92
+
93
+ it "should test wms example" do
94
+ @map = MapLayers::Map.new("map") do |map,page|
95
+ page << map.add_control(OpenLayers::Control::LayerSwitcher.new)
96
+ page << map.add_layer(OpenLayers::Layer::WMS.new( "OpenLayers WMS",
97
+ "http://labs.metacarta.com/wms/vmap0", {:layers => 'basic'} ))
98
+ page << map.zoom_to_max_extent()
99
+ end
100
+ html =<<EOS
101
+ <script defer="defer" type="text/javascript">
102
+ var map;
103
+ map = new OpenLayers.Map('map', {theme : false});
104
+ map.addControl(new OpenLayers.Control.LayerSwitcher());
105
+ map.addLayer(new OpenLayers.Layer.WMS("OpenLayers WMS","http://labs.metacarta.com/wms/vmap0",{layers : "basic"}));
106
+ map.zoomToMaxExtent();
107
+ </script>
108
+ EOS
109
+ @map.to_html.should == html
110
+ end
111
+
112
+ it "should test kml example" do
113
+ @map = MapLayers::Map.new("map") do |map,page|
114
+ page << map.add_layer(OpenLayers::Layer::GML.new("Places KML", "/places/kml", {:format=> MapLayers::JsExpr.new("OpenLayers.Format.KML")}))
115
+ end
116
+ html =<<EOS
117
+ <script defer="defer" type="text/javascript">
118
+ var map;
119
+ map = new OpenLayers.Map('map', {theme : false});
120
+ map.addLayer(new OpenLayers.Layer.GML("Places KML","/places/kml",{format : OpenLayers.Format.KML}));
121
+ </script>
122
+ EOS
123
+ @map.to_html.should == html
124
+ end
125
+
126
+ it "should test wfs example" do
127
+ @map = MapLayers::Map.new("map_div") do |map, page|
128
+ page << map.add_layer(OpenLayers::Layer::WFS.new("Places WFS", "/places/wfs", {:typename => "places"}, {:featureClass => MapLayers::JsExpr.new("OpenLayers.Feature.WFS")}))
129
+ end
130
+ html =<<EOS
131
+ <script defer="defer" type="text/javascript">
132
+ var map_div;
133
+ map_div = new OpenLayers.Map('map_div', {theme : false});
134
+ map_div.addLayer(new OpenLayers.Layer.WFS("Places WFS","/places/wfs",{typename : "places"},{featureClass : OpenLayers.Feature.WFS}));
135
+ </script>
136
+ EOS
137
+ @map.to_html.should == html
138
+ end
139
+
140
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe MapLayers do
4
+
5
+ describe ".const_missing" do
6
+
7
+ it "should return the class MapLayers::Layer::Google for GOOGLE" do
8
+ MapLayers::GOOGLE.class.to_s.should == "OpenLayers::Layer::Google"
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe MapLayers::ViewHelpers do
4
+
5
+ #subject {MapLayers::ViewHelpers.new}
6
+
7
+ describe "#map_layers_include" do
8
+ it "should return html" do
9
+ #subject.map_layers_include.should == ""
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe MapLayers do
4
+
5
+ describe ".const_missing" do
6
+
7
+ it "should return a class with a child of MapLayers" do
8
+ OpenLayers::Test.name.should == "OpenLayers::Test"
9
+ end
10
+
11
+ it "should return a class with a little child of MapLayers" do
12
+ OpenLayers::Test::Toto.name.should == "OpenLayers::Test::Toto"
13
+ end
14
+
15
+ end
16
+
17
+ describe "ApplicationController" do
18
+ subject {ApplicationController}
19
+
20
+ it "should have a map_layer method" do
21
+ subject.methods.include?("map_layer").should be_true
22
+ end
23
+
24
+ it "should have a map_layer_config method" do
25
+ subject.methods.include?("map_layers_config").should be_true
26
+ end
27
+
28
+ end
29
+
30
+ describe "PlacesController" do
31
+ subject {PlacesController}
32
+
33
+ it "should exist an application model" do
34
+ #puts subject.inspect
35
+ end
36
+
37
+ end
38
+
39
+ describe "TestMap" do
40
+ subject {TestMap.new}
41
+
42
+ describe "#projection" do
43
+
44
+ it "should return an openlayers projection" do
45
+ OpenLayers::Projection.should_receive(:new).with("4326")
46
+ subject.projection("4326")
47
+ end
48
+
49
+ end
50
+
51
+ describe "#map" do
52
+
53
+ it "should return a map" do
54
+ projection = OpenLayers::Projection.new("EPSG:900913")
55
+ OpenLayers::Projection.stub!(:new) {projection}
56
+ MapLayers::Map.should_receive(:new).with("map", :projection => projection, :controls => [])
57
+ subject.map
58
+ end
59
+
60
+ end
61
+ end
62
+
63
+ end
data/spec/rcov.opts ADDED
@@ -0,0 +1,2 @@
1
+ --exclude "spec/*,gems/*"
2
+ --rails
@@ -0,0 +1,98 @@
1
+ # encoding: utf-8
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+
4
+ require 'rubygems'
5
+ require 'bundler'
6
+ Bundler.setup(:default)
7
+
8
+ require 'active_support'
9
+ require 'action_controller'
10
+ require 'active_model'
11
+ require 'rails/railtie'
12
+
13
+ require File.expand_path(File.join(File.dirname(__FILE__), '../lib/map_layers'))
14
+ require File.expand_path(File.join(File.dirname(__FILE__), '../lib/map_layers/view_helpers'))
15
+
16
+ # Requires supporting files with custom matchers and macros, etc,
17
+ # in ./support/ and its subdirectories in alphabetic order.
18
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each {|f| require f}
19
+
20
+ class ApplicationController < ActionController::Base
21
+ include MapLayers
22
+ include MapLayers::ViewHelpers
23
+
24
+ self.view_paths = File.join(File.dirname(__FILE__), 'views')
25
+ respond_to :html, :kml
26
+ end
27
+
28
+ class PlacesController < ApplicationController
29
+
30
+ map_layer :place, :text => :placeName
31
+
32
+ end
33
+
34
+ class ActiveSupport::TestCase
35
+ setup do
36
+ @routes = Responders::Routes
37
+ end
38
+ end
39
+
40
+ class Model
41
+ include ActiveModel::Conversion
42
+ include ActiveModel::Validations
43
+
44
+ attr_accessor :persisted, :updated_at
45
+ alias :persisted? :persisted
46
+
47
+ def persisted?
48
+ @persisted
49
+ end
50
+
51
+ def to_xml(*args)
52
+ "<xml />"
53
+ end
54
+
55
+ def initialize(updated_at=nil)
56
+ @persisted = true
57
+ self.updated_at = updated_at
58
+ end
59
+ end
60
+
61
+ class TestMap < Model
62
+ include MapLayers
63
+ include MapLayers::ViewHelpers
64
+
65
+ def projection(name)
66
+ OpenLayers::Projection.new(name)
67
+ end
68
+
69
+ def id
70
+ "map"
71
+ end
72
+
73
+ def controls
74
+ []
75
+ end
76
+
77
+ def map
78
+ @map ||= MapLayers::Map.new(id, :projection => projection("EPSG:900913"), :controls => controls)
79
+ end
80
+
81
+ end
82
+
83
+ class Place < Model
84
+ attr_accessor :placeName, :countryCode, :postalCode, :lat, :lng
85
+ end
86
+
87
+ # @place = ::Place.new
88
+ # @place.stub!(:class).and_return(::Place)
89
+ # @place.stub!(:placeName).and_return("place name")
90
+ # @place.stub!(:countryCode).and_return("92")
91
+ # @place.stub!(:postalCode).and_return("92000")
92
+ # @place.stub!(:lat).and_return("1")
93
+ # @place.stub!(:lng).and_return("1")
94
+ # @place.stub!(:id).and_return(37)
95
+ # @place.stub!(:new_record?).and_return(false)
96
+ # @place.stub!(:errors).and_return(mock('errors', :[] => nil))
97
+ # @place.stub!(:to_key).and_return(nil)
98
+ # @place.stub!(:persisted?).and_return(nil)
@@ -0,0 +1,21 @@
1
+ namespace :map_layers do
2
+
3
+ desc "Install development libraries"
4
+ task :install_dev_lib do
5
+ plugin_root = File.join(File.dirname(__FILE__), "..")
6
+ copy_files("/OpenLayers/lib", "/public/javascripts", plugin_root)
7
+ end
8
+
9
+ def copy_files(source_path, destination_path, plugin_root)
10
+ source, destination = File.join(plugin_root, source_path), File.join(RAILS_ROOT, destination_path)
11
+ FileUtils.mkdir(destination) unless File.exist?(destination)
12
+ FileUtils.cp_r(source, destination)
13
+ end
14
+
15
+ desc "Remove development libraries"
16
+ task :uninstall_dev_lib do
17
+ FileUtils.rm_r(File.join(RAILS_ROOT, "/public/javascripts/lib"))
18
+ end
19
+
20
+
21
+ end
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,188 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: map_layers
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
11
+ platform: ruby
12
+ authors:
13
+ - Luc Donnet
14
+ - Alban Peignier
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-08-24 00:00:00 +02:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 7
29
+ segments:
30
+ - 3
31
+ - 0
32
+ - 0
33
+ version: 3.0.0
34
+ requirement: *id001
35
+ type: :development
36
+ name: rails
37
+ prerelease: false
38
+ - !ruby/object:Gem::Dependency
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 15
45
+ segments:
46
+ - 2
47
+ - 0
48
+ - 0
49
+ version: 2.0.0
50
+ requirement: *id002
51
+ type: :development
52
+ name: rspec
53
+ prerelease: false
54
+ - !ruby/object:Gem::Dependency
55
+ version_requirements: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ hash: 15
61
+ segments:
62
+ - 2
63
+ - 0
64
+ - 0
65
+ version: 2.0.0
66
+ requirement: *id003
67
+ type: :development
68
+ name: rspec-rails
69
+ prerelease: false
70
+ - !ruby/object:Gem::Dependency
71
+ version_requirements: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ requirement: *id004
81
+ type: :development
82
+ name: rake
83
+ prerelease: false
84
+ - !ruby/object:Gem::Dependency
85
+ version_requirements: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ requirement: *id005
95
+ type: :development
96
+ name: autotest-rails
97
+ prerelease: false
98
+ - !ruby/object:Gem::Dependency
99
+ version_requirements: &id006 !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ requirement: *id006
109
+ type: :development
110
+ name: autotest-notification
111
+ prerelease: false
112
+ description: library dedicated to generate OSM javascript
113
+ email:
114
+ - luc.donnet@dryade.net
115
+ - alban.peignier@dryade.net
116
+ executables: []
117
+
118
+ extensions: []
119
+
120
+ extra_rdoc_files: []
121
+
122
+ files:
123
+ - .autotest
124
+ - .gitignore
125
+ - .rspec
126
+ - Gemfile
127
+ - Gemfile.lock
128
+ - MIT-LICENSE
129
+ - README
130
+ - Rakefile
131
+ - autotest/discover.rb
132
+ - init.rb
133
+ - install.rb
134
+ - lib/map_layers.rb
135
+ - lib/map_layers/#geonames.rb#
136
+ - lib/map_layers/geonames.rb
137
+ - lib/map_layers/js_wrapper.rb
138
+ - lib/map_layers/map.rb
139
+ - lib/map_layers/open_layers.rb
140
+ - lib/map_layers/version.rb
141
+ - lib/map_layers/view_helpers.rb
142
+ - map_layers.gemspec
143
+ - rails/init.rb
144
+ - spec/lib/map_layers/js_wrapper_spec.rb
145
+ - spec/lib/map_layers/map_spec.rb
146
+ - spec/lib/map_layers/view_helpers_spec.rb
147
+ - spec/lib/map_layers_spec.rb
148
+ - spec/rcov.opts
149
+ - spec/spec_helper.rb
150
+ - spec/spec_helper.rb~
151
+ - tasks/map_layers_tasks.rake
152
+ - uninstall.rb
153
+ has_rdoc: true
154
+ homepage: http://github.com/ldonnet/map_layers
155
+ licenses: []
156
+
157
+ post_install_message:
158
+ rdoc_options: []
159
+
160
+ require_paths:
161
+ - lib
162
+ required_ruby_version: !ruby/object:Gem::Requirement
163
+ none: false
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ hash: 3
168
+ segments:
169
+ - 0
170
+ version: "0"
171
+ required_rubygems_version: !ruby/object:Gem::Requirement
172
+ none: false
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ hash: 3
177
+ segments:
178
+ - 0
179
+ version: "0"
180
+ requirements: []
181
+
182
+ rubyforge_project: map_layers
183
+ rubygems_version: 1.3.7
184
+ signing_key:
185
+ specification_version: 3
186
+ summary: library dedicated to generate OSM javascript
187
+ test_files: []
188
+