radiant-event_map-extension 1.3.5 → 1.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/event_map_extension.rb +6 -4
- data/lib/grid_ref.rb +1 -27
- data/lib/mappable.rb +1 -1
- data/lib/radiant-event_map-extension.rb +1 -1
- data/lib/string_conversions.rb +36 -0
- data/spec/lib/conversions_spec.rb +52 -0
- data/spec/lib/grid_ref_spec.rb +1 -30
- metadata +8 -6
- data/radiant-event_map-extension-1.3.4.gem +0 -0
data/event_map_extension.rb
CHANGED
@@ -13,10 +13,12 @@ class EventMapExtension < Radiant::Extension
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def activate
|
16
|
-
require 'angle_conversions'
|
17
|
-
require '
|
18
|
-
|
19
|
-
|
16
|
+
require 'angle_conversions' # adds degree/radian conversions to Numeric
|
17
|
+
require 'string_conversions' # adds lat/long and gridref conversions to String
|
18
|
+
require 'grid_ref' # converts coordinates from UK grid references to lat/long
|
19
|
+
EventVenue.send :include, Mappable # adds geolocation on validation
|
20
|
+
Page.send :include, EventMapTags # defines a very basic events:googlemap tag
|
21
|
+
# the real work is done when the EventVenuesController builds javascript
|
20
22
|
end
|
21
23
|
|
22
24
|
end
|
data/lib/grid_ref.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# adapted from Geography::NationalGrid by and (c) P Kent
|
2
2
|
# with reference to the Ordnance Survey guide to coordinate systems in the UK
|
3
3
|
# http://www.ordnancesurvey.co.uk/oswebsite/gps/information/coordinatesystemsinfo/guidecontents/
|
4
|
+
|
4
5
|
class Ellipsoid
|
5
6
|
attr_accessor :a, :b, :e2
|
6
7
|
|
@@ -263,30 +264,3 @@ private
|
|
263
264
|
end
|
264
265
|
|
265
266
|
end
|
266
|
-
|
267
|
-
class String
|
268
|
-
def is_gridref?
|
269
|
-
!!(self.upcase =~ /^(H(P|T|U|Y|Z)|N(A|B|C|D|F|G|H|J|K|L|M|N|O|R|S|T|U|W|X|Y|Z)|OV|S(C|D|E|G|H|J|K|M|N|O|P|R|S|T|U|W|X|Y|Z)|T(A|F|G|L|M|Q|R|V)){1}\d{4}(NE|NW|SE|SW)?$|((H(P|T|U|Y|Z)|N(A|B|C|D|F|G|H|J|K|L|M|N|O|R|S|T|U|W|X|Y|Z)|OV|S(C|D|E|G|H|J|K|M|N|O|P|R|S|T|U|W|X|Y|Z)|T(A|F|G|L|M|Q|R|V)){1}(\d{4}|\d{6}|\d{8}|\d{10}))$/)
|
270
|
-
end
|
271
|
-
|
272
|
-
def is_latlng?
|
273
|
-
!!(self =~ /(-?\d+\.\d+)[,\s]+(-?\d+\.\d+)/)
|
274
|
-
end
|
275
|
-
|
276
|
-
def to_latlng(options = {})
|
277
|
-
if is_latlng?
|
278
|
-
self
|
279
|
-
elsif is_gridref?
|
280
|
-
GridRef.new(self, options).to_latlng
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
def to_wgs84(options = {})
|
285
|
-
if is_latlng?
|
286
|
-
self
|
287
|
-
elsif is_gridref?
|
288
|
-
GridRef.new(self, options.merge(:datum => :wgs84)).to_latlng
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
end
|
data/lib/mappable.rb
CHANGED
@@ -55,7 +55,7 @@ private
|
|
55
55
|
else
|
56
56
|
bias = Radiant::Config['event_map.zone'] || 'uk'
|
57
57
|
geo = Geokit::Geocoders::MultiGeocoder.geocode(location, :bias => bias)
|
58
|
-
errors.add(:postcode, "Could not Geocode location: please specify here")
|
58
|
+
errors.add(:postcode, "Could not Geocode location: please specify here") unless geo.success
|
59
59
|
self.lat, self.lng = geo.lat, geo.lng if geo.success
|
60
60
|
end
|
61
61
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module RadiantEventMapExtension
|
2
|
-
VERSION = '1.3.
|
2
|
+
VERSION = '1.3.6'
|
3
3
|
SUMMARY = %Q{Event geocoding and map extension for Radiant CMS}
|
4
4
|
DESCRIPTION = "Small additions to the event_calendar that geocode calendar events and display on a google map. Separated here because perhaps only of interest to a few."
|
5
5
|
URL = "http://github.com/radiant/radiant-event_calendar-extension"
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class String
|
2
|
+
require 'grid_ref'
|
3
|
+
attr_accessor :coordinates
|
4
|
+
|
5
|
+
def is_gridref?
|
6
|
+
!!(self.upcase =~ /^(H(P|T|U|Y|Z)|N(A|B|C|D|F|G|H|J|K|L|M|N|O|R|S|T|U|W|X|Y|Z)|OV|S(C|D|E|G|H|J|K|M|N|O|P|R|S|T|U|W|X|Y|Z)|T(A|F|G|L|M|Q|R|V)){1}\d{4}(NE|NW|SE|SW)?$|((H(P|T|U|Y|Z)|N(A|B|C|D|F|G|H|J|K|L|M|N|O|R|S|T|U|W|X|Y|Z)|OV|S(C|D|E|G|H|J|K|M|N|O|P|R|S|T|U|W|X|Y|Z)|T(A|F|G|L|M|Q|R|V)){1}(\d{4}|\d{6}|\d{8}|\d{10}))$/)
|
7
|
+
end
|
8
|
+
|
9
|
+
def is_latlng?
|
10
|
+
!!coordinates
|
11
|
+
end
|
12
|
+
|
13
|
+
def coordinates
|
14
|
+
if matches = self.match(/(-?\d+\.\d+)[,\s]+(-?\d+\.\d+)/)
|
15
|
+
matches[1,2].join(', ')
|
16
|
+
else
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_latlng(options = {})
|
22
|
+
if is_gridref?
|
23
|
+
GridRef.new(self, options).to_latlng
|
24
|
+
else
|
25
|
+
self.coordinates
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_wgs84(options = {})
|
30
|
+
if is_gridref?
|
31
|
+
GridRef.new(self, options.merge(:datum => :wgs84)).to_latlng
|
32
|
+
else
|
33
|
+
self.coordinates
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe String do
|
4
|
+
describe "that is already a lat/long pair" do
|
5
|
+
it "should respond negatively to .is_gridref?" do
|
6
|
+
"54.07469997904575,-3.175048828125".is_gridref?.should be_false
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should respond positively to .is_latlng?" do
|
10
|
+
"54.07469997904575,-3.175048828125".is_latlng?.should be_true
|
11
|
+
"54.07469997904575 -3.175048828125".is_latlng?.should be_true
|
12
|
+
"54.07469997904575 3.175048828125".is_latlng?.should be_true
|
13
|
+
"54.0 -3.0".is_latlng?.should be_true
|
14
|
+
"54 3".is_latlng?.should be_false
|
15
|
+
"543".is_latlng?.should be_false
|
16
|
+
"54-3".is_latlng?.should be_false
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should respond to .to_latlng with coordinates" do
|
20
|
+
"54.07469997904575 -3.175048828125".to_latlng.should == "54.07469997904575, -3.175048828125"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should convert to grid ref"
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "that is a grid reference" do
|
27
|
+
it "should respond positively to .is_gridref?" do
|
28
|
+
"SD123456".is_gridref?.should be_true
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should respond to .to_latlng with coordinates" do
|
32
|
+
"SD2873178452".to_latlng.should == "54.196698, -3.092537"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should pass through options to the grid ref" do
|
36
|
+
"SD2873178452".to_latlng(:datum => :wgs84).should == "54.19685, -3.093901"
|
37
|
+
"SD2873178452".to_wgs84.should == "54.19685, -3.093901"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "that is a not recognised as a grid reference" do
|
42
|
+
it "should respond negatively to .is_gridref?" do
|
43
|
+
"banana".is_gridref?.should be_false
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should return nil to .to_latlng" do
|
47
|
+
lambda{ "banana".to_latlng }.should_not raise_error
|
48
|
+
"banana".to_latlng.should be_nil
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
data/spec/lib/grid_ref_spec.rb
CHANGED
@@ -9,7 +9,7 @@ describe GridRef do
|
|
9
9
|
lambda{ GridRef.new("SD1234567890") }.should_not raise_error
|
10
10
|
end
|
11
11
|
|
12
|
-
describe "
|
12
|
+
describe "standard transformation" do
|
13
13
|
before do
|
14
14
|
@gr = GridRef.new("SD2873178452")
|
15
15
|
end
|
@@ -59,32 +59,3 @@ describe GridRef do
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
62
|
-
|
63
|
-
describe String do
|
64
|
-
describe "that is a grid reference" do
|
65
|
-
it "should respond positively to .is_gridref?" do
|
66
|
-
"SD123456".is_gridref?.should be_true
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should respond to .to_latlng with coordinates" do
|
70
|
-
"SD2873178452".to_latlng.should == "54.196698, -3.092537"
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should pass through options to the grid ref" do
|
74
|
-
"SD2873178452".to_latlng(:datum => :wgs84).should == "54.19685, -3.093901"
|
75
|
-
"SD2873178452".to_wgs84.should == "54.19685, -3.093901"
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe "that is a not recognised as a grid reference" do
|
80
|
-
it "should respond negatively to .is_gridref?" do
|
81
|
-
"banana".is_gridref?.should be_false
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should return nil to .to_latlng" do
|
85
|
-
lambda{ "banana".to_latlng }.should_not raise_error
|
86
|
-
"banana".to_latlng.should be_nil
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: radiant-event_map-extension
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 1.3.
|
9
|
+
- 6
|
10
|
+
version: 1.3.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- William Ross
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-07-
|
18
|
+
date: 2011-07-28 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -78,13 +78,14 @@ files:
|
|
78
78
|
- lib/grid_ref.rb
|
79
79
|
- lib/mappable.rb
|
80
80
|
- lib/radiant-event_map-extension.rb
|
81
|
+
- lib/string_conversions.rb
|
81
82
|
- lib/tasks/event_map_extension_tasks.rake
|
82
83
|
- public/images/map_icons/pink-dot.png
|
83
84
|
- public/images/map_icons/shadow.png
|
84
|
-
- radiant-event_map-extension-1.3.4.gem
|
85
85
|
- radiant-event_map-extension.gemspec
|
86
86
|
- Rakefile
|
87
87
|
- README.md
|
88
|
+
- spec/lib/conversions_spec.rb
|
88
89
|
- spec/lib/grid_ref_spec.rb
|
89
90
|
- spec/spec.opts
|
90
91
|
- spec/spec_helper.rb
|
@@ -93,7 +94,7 @@ has_rdoc: true
|
|
93
94
|
homepage: http://github.com/radiant/radiant-event_calendar-extension
|
94
95
|
licenses: []
|
95
96
|
|
96
|
-
post_install_message: "\n Add this to your radiant project with:\n\n config.gem 'radiant-event_map-extension', :version => '~> 1.3.
|
97
|
+
post_install_message: "\n Add this to your radiant project with:\n\n config.gem 'radiant-event_map-extension', :version => '~> 1.3.6'\n\n "
|
97
98
|
rdoc_options: []
|
98
99
|
|
99
100
|
require_paths:
|
@@ -124,6 +125,7 @@ signing_key:
|
|
124
125
|
specification_version: 3
|
125
126
|
summary: Event geocoding and map extension for Radiant CMS
|
126
127
|
test_files:
|
128
|
+
- spec/lib/conversions_spec.rb
|
127
129
|
- spec/lib/grid_ref_spec.rb
|
128
130
|
- spec/spec.opts
|
129
131
|
- spec/spec_helper.rb
|
Binary file
|