ym4r 0.4.1 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,71 +0,0 @@
1
- module Ym4r
2
- module YahooMaps
3
- module Flash
4
-
5
- module MappingObject
6
- attr_reader :variable
7
-
8
- #special method for add_event_listener since the user need to pass reference to methods and the general method_missing won't work for that
9
- def add_event_listener(event, method, context)
10
- "#{to_javascript}.addEventListener(#{event},#{method},#{context});\n"
11
- end
12
-
13
- def remove_event_listener(event, method, context)
14
- "#{to_javascript}.removeEventListener(#{event},#{method},#{context});\n"
15
- end
16
-
17
- #creates javascript code for missing methods
18
- def method_missing(name,*args)
19
- args.collect! do |arg|
20
- if arg.is_a?(MappingObject)
21
- arg.to_javascript
22
- elsif arg.is_a?(String)
23
- "\"#{escape_javascript(arg)}\""
24
- else
25
- arg.to_s
26
- end
27
- end
28
- "#{to_javascript}.#{javascriptify(name.to_s)}(#{args.join(",")});\n"
29
- end
30
-
31
- #lifted from rails
32
- def escape_javascript(javascript)
33
- javascript.gsub(/\r\n|\n|\r/, "\\n").gsub(/["']/) { |m| "\\#{m}" }
34
- end
35
-
36
- #transform a ruby-type method name (like qsd_fghj) to a Yahoo! Map style one (like qsdFghj)
37
- def javascriptify(method_name)
38
- method_name.gsub(/_(\w)/){|s| $1.upcase}
39
- end
40
-
41
- #Declare Mapping Object (Map, Tool, Marker,...) of name variable
42
- def declare(variable)
43
- @variable = variable
44
- "var #{variable} = #{create};\n"
45
- end
46
-
47
- #Returns a Javascript script representing the object
48
- def to_javascript
49
- unless @variable.nil?
50
- @variable
51
- else
52
- create
53
- end
54
- end
55
-
56
- #Creates a Mapping Object in Javascript
57
- #To be implemented by subclasses if needed
58
- def create
59
- end
60
- end
61
-
62
- class Variable
63
- include MappingObject
64
-
65
- def initialize(variable)
66
- @variable = variable
67
- end
68
- end
69
- end
70
- end
71
- end
@@ -1,43 +0,0 @@
1
- module Ym4r
2
- module YahooMaps
3
- module Flash
4
- module Marker
5
- EVENT_INITIALIZE = "Marker.EVENT_INITIALIZE"
6
- end
7
-
8
- class CustomPOIMarker < Struct.new(:index, :title, :description, :marker_color, :stroke_color)
9
- include MappingObject
10
-
11
- def create
12
- "new CustomPOIMarker('#{index}','#{title}','#{description}','#{marker_color}','#{stroke_color}')";
13
- end
14
- end
15
-
16
- class CustomImageMarker < Struct.new(:url)
17
- include MappingObject
18
-
19
- def create
20
- "new CutomImageMarker('#{url}')"
21
- end
22
- end
23
-
24
- class CustomSWFMarker < Struct.new(:url)
25
- include MappingObject
26
-
27
- def create
28
- "new CustomSWFMarker('#{url}')"
29
- end
30
- end
31
-
32
- class WaypointMarker < Struct.new(:index)
33
- include MappingObject
34
-
35
- def create
36
- "new WaypointMarker('#{index}')"
37
- end
38
- end
39
- end
40
- end
41
- end
42
-
43
-
@@ -1,44 +0,0 @@
1
- module Ym4r
2
- module YahooMaps
3
- module Flash
4
- module Overlay
5
- EVENT_INITIALIZE = "Overlay.EVENT_INITIALIZE"
6
- end
7
-
8
- class CustomSWFOverlay < Struct.new(:url)
9
- include MappingObject
10
-
11
- def create
12
- "new CustomSWFOverlay('#{url}')"
13
- end
14
- end
15
-
16
- class GeoRSSOverlay < Struct.new(:url)
17
- include MappingObject
18
-
19
- def create
20
- "new GeoRSSOverlay('#{url}')"
21
- end
22
- end
23
-
24
- class LocalSearchOverlay
25
- include MappingObject
26
-
27
- EVENT_SEARCH_ERROR = "LocalSearchOverlay.EVENT_SEARCH_ERROR"
28
- EVENT_SEARCH_SUCCESS = "LocalSearchOverlay.EVENT_SEARCH_SUCCESS"
29
-
30
- def create
31
- "new LocalSearchOverlay()"
32
- end
33
- end
34
-
35
- class TrafficOverlay
36
- include MappingObject
37
-
38
- def create
39
- "new TrafficOverlay()"
40
- end
41
- end
42
- end
43
- end
44
- end
@@ -1,30 +0,0 @@
1
- module Ym4r
2
- module YahooMaps
3
- module Flash
4
- module Tool
5
- EVENT_INITIALIZE = "Tool.EVENT_INITIALIZE"
6
- end
7
-
8
- class CustomSWFTool < Struct.new(:url,:icon_url)
9
- include MappingObject
10
-
11
- EVENT_LOADED = "CustomSWFTool.EVENT_LOADED"
12
-
13
- def create
14
- "new CustomSWFTool('#{url}','#{icon_url}')"
15
- end
16
- end
17
-
18
- class PanTool
19
- include MappingObject
20
-
21
- EVENT_DRAG_STOP = "PanTool.EVENT_DRAG_STOP"
22
- EVENT_DRAG_START = "PanTool.EVENT_DRAG_START"
23
-
24
- def create
25
- "new PanTool()"
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,33 +0,0 @@
1
- module Ym4r
2
- module YahooMaps
3
- module Flash
4
- module Widget
5
- EVENT_INITIALIZE = "Widget.EVENT_INITIALIZE"
6
- end
7
-
8
- class NavigatorWidget
9
- include MappingObject
10
-
11
- def create
12
- "new NavigatorWidget()"
13
- end
14
- end
15
-
16
- class SatelliteControlWidget
17
- include MappingObject
18
-
19
- def create
20
- "new SatelliteControlWidget()"
21
- end
22
- end
23
-
24
- class ToolBarWidget
25
- include MappingObject
26
-
27
- def create
28
- "new ToolBarWidget()"
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,75 +0,0 @@
1
- $:.unshift(File.dirname(__FILE__) + '/../lib')
2
-
3
- require 'ym4r/google_maps'
4
- require 'ym4r/google_maps/geocoding'
5
- require 'test/unit'
6
-
7
- include Ym4r::GoogleMaps
8
-
9
- class TestGoogleMaps< Test::Unit::TestCase
10
- def test_javascriptify_method
11
- assert_equal("addOverlayToHello",MappingObject::javascriptify_method("add_overlay_to_hello"))
12
- end
13
-
14
- def test_javascriptify_variable_mapping_object
15
- map = GMap.new("div")
16
- assert_equal(map.to_javascript,MappingObject::javascriptify_variable(map))
17
- end
18
-
19
- def test_javascriptify_variable_numeric
20
- assert_equal("123.4",MappingObject::javascriptify_variable(123.4))
21
- end
22
-
23
- def test_javascriptify_variable_array
24
- map = GMap.new("div")
25
- assert_equal("[123.4,#{map.to_javascript},[123.4,#{map.to_javascript}]]",MappingObject::javascriptify_variable([123.4,map,[123.4,map]]))
26
- end
27
-
28
- def test_javascriptify_variable_hash
29
- map = GMap.new("div")
30
- test_str = MappingObject::javascriptify_variable("hello" => map, "chopotopoto" => [123.55,map])
31
- assert("{hello : #{map.to_javascript},chopotopoto : [123.55,#{map.to_javascript}]}" == test_str || "{chopotopoto : [123.55,#{map.to_javascript}],hello : #{map.to_javascript}}" == test_str)
32
- end
33
-
34
- def test_method_call_on_mapping_object
35
- map = GMap.new("div","map")
36
- assert_equal("map.addHello(123.4);",map.add_hello(123.4).to_s)
37
- end
38
-
39
- def test_nested_calls_on_mapping_object
40
- gmap = GMap.new("div","map")
41
- assert_equal("map.addHello(map.hoYoYo(123.4),map);",gmap.add_hello(gmap.ho_yo_yo(123.4),gmap).to_s)
42
- end
43
-
44
- def test_declare_variable_latlng
45
- point = GLatLng.new([123.4,123.6])
46
- assert_equal("var point = new GLatLng(123.4,123.6);",point.declare("point"))
47
- assert_equal("point",point.variable)
48
- end
49
-
50
- def test_array_indexing
51
- obj = Variable.new("obj")
52
- assert_equal("obj[0]",obj[0].variable)
53
- end
54
-
55
- def test_google_maps_geocoding
56
- placemarks = Geocoding.get("Rue Clovis Paris")
57
- assert_equal(Geocoding::GEO_SUCCESS,placemarks.status)
58
- assert_equal(1,placemarks.length)
59
- placemark = placemarks[0]
60
- assert_equal("FR",placemark.country_code)
61
- assert_equal("Paris",placemark.locality)
62
- assert_equal("75005",placemark.postal_code)
63
- end
64
-
65
- def test_google_maps_pakistan
66
- placemarks = Geocoding.get("Lahore PK")
67
- assert_equal(Geocoding::GEO_SUCCESS,placemarks.status)
68
- assert_equal(1,placemarks.length)
69
- placemark = placemarks[0]
70
- assert_equal("PK",placemark.country_code)
71
- assert_equal("Lahore",placemark.locality)
72
- assert_equal("",placemark.thoroughfare)
73
- end
74
-
75
- end