porth-kml 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/Gemfile +7 -0
- data/LICENSE +21 -0
- data/README.md +105 -0
- data/Rakefile +7 -0
- data/lib/porth-kml.rb +7 -0
- data/lib/porth-kml/version.rb +5 -0
- data/lib/porth/format/kml.rb +16 -0
- data/porth-kml.gemspec +29 -0
- data/spec/porth-kml_spec.rb +37 -0
- data/spec/spec_helper.rb +5 -0
- data/test/fixtures/block.rb +14 -0
- data/test/fixtures/instance_variable.rb +9 -0
- metadata +176 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2012 Matt Connolly <matt.connolly@me.com>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
# porth-kml (Plain Old Ruby Template Handler - KML output)
|
2
|
+
|
3
|
+
Adds KML (.kml) support to 'porth' (Plain Old Ruby Template Handler) gem.
|
4
|
+
|
5
|
+
This allows a view written in plain ruby to create a tree of kml objects using the ruby_kml gem
|
6
|
+
and have that kml be rendered to the browser.
|
7
|
+
|
8
|
+
## Requirements
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this to your project's Gemfile and run `$ bundle install`
|
13
|
+
|
14
|
+
``` ruby
|
15
|
+
gem 'porth-kml'
|
16
|
+
```
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
Add the ".kml" mime time to your rails app's config/initializers/mime_types.rb:
|
21
|
+
|
22
|
+
``` ruby
|
23
|
+
Mime::Type.register "application/vnd.google-earth.kml+xml", :kml
|
24
|
+
```
|
25
|
+
|
26
|
+
Add ":kml" to your controller's responds_to calls, for example:
|
27
|
+
|
28
|
+
``` ruby
|
29
|
+
class PeopleController < ApplicationController
|
30
|
+
|
31
|
+
respond_to :json, :xml, :kml, :html
|
32
|
+
|
33
|
+
# GET /people
|
34
|
+
# GET /people.json
|
35
|
+
def index
|
36
|
+
@people = Person.all
|
37
|
+
|
38
|
+
respond_with @people
|
39
|
+
end
|
40
|
+
|
41
|
+
# GET /people/1
|
42
|
+
# GET /people/1.json
|
43
|
+
def show
|
44
|
+
@person = Person.find(params[:id])
|
45
|
+
|
46
|
+
respond_with @person
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
Then your view must return a KMLFile object, for example:
|
51
|
+
|
52
|
+
``` ruby
|
53
|
+
require 'ruby_kml'
|
54
|
+
|
55
|
+
kml = KMLFile.new
|
56
|
+
folder= KML::Folder.new(:name => 'People')
|
57
|
+
|
58
|
+
@person.each do |person|
|
59
|
+
point = KML::Point.new :coordinates => { :lat => person.latitude,
|
60
|
+
:lng => person.longitude }
|
61
|
+
place = KML::Placemark.new :geometry => point, :name => person.name
|
62
|
+
folder.features << place
|
63
|
+
end
|
64
|
+
|
65
|
+
kml.objects << folder
|
66
|
+
kml
|
67
|
+
```
|
68
|
+
|
69
|
+
etc...
|
70
|
+
|
71
|
+
## Dependencies
|
72
|
+
|
73
|
+
Runtime dependencies:
|
74
|
+
|
75
|
+
* porth
|
76
|
+
* ruby_kml
|
77
|
+
* action_pack (>= 3.1) (to be consistent with porth)
|
78
|
+
* active_record (>= 3.1) (to be consistent with above)
|
79
|
+
|
80
|
+
Development dependencies:
|
81
|
+
|
82
|
+
* rpsec
|
83
|
+
* rake
|
84
|
+
|
85
|
+
## Compatibility
|
86
|
+
|
87
|
+
* MRI 1.9.2+
|
88
|
+
|
89
|
+
* rails >= 3.1 (to be consistent with Porth)
|
90
|
+
|
91
|
+
## Contributing
|
92
|
+
|
93
|
+
1. Fork
|
94
|
+
2. Install dependancies by running `$ bundle install`
|
95
|
+
3. Write tests and code
|
96
|
+
4. Make sure the tests pass by running `$ rake test`
|
97
|
+
5. Push and send a pull request on GitHub
|
98
|
+
|
99
|
+
## Credits
|
100
|
+
|
101
|
+
Special thanks to Tate Johnson (et al) for making Porth!
|
102
|
+
|
103
|
+
## Copyright
|
104
|
+
|
105
|
+
Copyright © 2012 Matt Connolly. Released under the MIT license. See LICENSE.
|
data/Rakefile
ADDED
data/lib/porth-kml.rb
ADDED
data/porth-kml.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "porth-kml/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "porth-kml"
|
7
|
+
s.version = Porth::KML::VERSION
|
8
|
+
s.authors = ["Matt Connolly"]
|
9
|
+
s.email = ["matt.connolly@me.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Plain Old Ruby Template KML handler}
|
12
|
+
s.description = %q{Plain Old Ruby Template KML handler}
|
13
|
+
|
14
|
+
s.rubyforge_project = "porth-kml"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_runtime_dependency 'porth'
|
23
|
+
s.add_runtime_dependency 'ruby_kml'
|
24
|
+
s.add_runtime_dependency 'actionpack', '>= 3.1.0', '< 4.0.0'
|
25
|
+
s.add_runtime_dependency 'activerecord', '>= 3.1.0', '< 4.0.0'
|
26
|
+
|
27
|
+
s.add_development_dependency 'rspec'
|
28
|
+
s.add_development_dependency 'rake', '~> 0.9.2'
|
29
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "rspec"
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'rexml/document'
|
4
|
+
|
5
|
+
describe "Render to plist" do
|
6
|
+
|
7
|
+
|
8
|
+
def template_dir
|
9
|
+
File.expand_path('../../test/fixtures', __FILE__)
|
10
|
+
end
|
11
|
+
|
12
|
+
def render file, format, assigns = {}
|
13
|
+
view = ActionView::Base.new(template_dir, assigns, @controller, [format]).tap do |view|
|
14
|
+
#view.lookup_context.freeze_formats [format]
|
15
|
+
end
|
16
|
+
view.render :file => file
|
17
|
+
end
|
18
|
+
|
19
|
+
it "outputs an array of hashes as a plist" do
|
20
|
+
|
21
|
+
output = render('block', :kml)
|
22
|
+
|
23
|
+
xml = REXML::Document.new(output)
|
24
|
+
placemarks = xml.elements.to_a("/kml/Folder/Placemark")
|
25
|
+
placemarks.length.should == 2
|
26
|
+
placemarks[0].elements['name'].text.should == 'Test place #1'
|
27
|
+
placemarks[1].elements['name'].text.should == 'Test place #2'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "outputs an instance variable into a plist" do
|
31
|
+
|
32
|
+
output = render('instance_variable', :kml, 'foo' => 'bar')
|
33
|
+
|
34
|
+
xml = REXML::Document.new(output)
|
35
|
+
xml.elements['/kml/Folder/Placemark/name'].text.should == 'bar'
|
36
|
+
end
|
37
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'ruby_kml'
|
2
|
+
|
3
|
+
kml = KMLFile.new
|
4
|
+
folder= KML::Folder.new
|
5
|
+
|
6
|
+
(1..2).map do |n|
|
7
|
+
point = KML::Point.new :coordinates => { :lat => 1+n.to_f,
|
8
|
+
:lng => 2+n.to_f }
|
9
|
+
place = KML::Placemark.new :geometry => point, :name => "Test place ##{n}"
|
10
|
+
folder.features << place
|
11
|
+
end
|
12
|
+
|
13
|
+
kml.objects << folder
|
14
|
+
kml
|
metadata
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: porth-kml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matt Connolly
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: porth
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: ruby_kml
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: actionpack
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 3.1.0
|
54
|
+
- - <
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 4.0.0
|
57
|
+
type: :runtime
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 3.1.0
|
65
|
+
- - <
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 4.0.0
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: activerecord
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.1.0
|
76
|
+
- - <
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 4.0.0
|
79
|
+
type: :runtime
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 3.1.0
|
87
|
+
- - <
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 4.0.0
|
90
|
+
- !ruby/object:Gem::Dependency
|
91
|
+
name: rspec
|
92
|
+
requirement: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
type: :development
|
99
|
+
prerelease: false
|
100
|
+
version_requirements: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ! '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
- !ruby/object:Gem::Dependency
|
107
|
+
name: rake
|
108
|
+
requirement: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ~>
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: 0.9.2
|
114
|
+
type: :development
|
115
|
+
prerelease: false
|
116
|
+
version_requirements: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ~>
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: 0.9.2
|
122
|
+
description: Plain Old Ruby Template KML handler
|
123
|
+
email:
|
124
|
+
- matt.connolly@me.com
|
125
|
+
executables: []
|
126
|
+
extensions: []
|
127
|
+
extra_rdoc_files: []
|
128
|
+
files:
|
129
|
+
- .gitignore
|
130
|
+
- Gemfile
|
131
|
+
- LICENSE
|
132
|
+
- README.md
|
133
|
+
- Rakefile
|
134
|
+
- lib/porth-kml.rb
|
135
|
+
- lib/porth-kml/version.rb
|
136
|
+
- lib/porth/format/kml.rb
|
137
|
+
- porth-kml.gemspec
|
138
|
+
- spec/porth-kml_spec.rb
|
139
|
+
- spec/spec_helper.rb
|
140
|
+
- test/fixtures/block.rb
|
141
|
+
- test/fixtures/instance_variable.rb
|
142
|
+
homepage: ''
|
143
|
+
licenses: []
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
none: false
|
150
|
+
requirements:
|
151
|
+
- - ! '>='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
segments:
|
155
|
+
- 0
|
156
|
+
hash: -449070793084796226
|
157
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
|
+
none: false
|
159
|
+
requirements:
|
160
|
+
- - ! '>='
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
segments:
|
164
|
+
- 0
|
165
|
+
hash: -449070793084796226
|
166
|
+
requirements: []
|
167
|
+
rubyforge_project: porth-kml
|
168
|
+
rubygems_version: 1.8.23
|
169
|
+
signing_key:
|
170
|
+
specification_version: 3
|
171
|
+
summary: Plain Old Ruby Template KML handler
|
172
|
+
test_files:
|
173
|
+
- spec/porth-kml_spec.rb
|
174
|
+
- spec/spec_helper.rb
|
175
|
+
- test/fixtures/block.rb
|
176
|
+
- test/fixtures/instance_variable.rb
|