mapfish 1.3.3 → 1.3.4
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.
- data/README +26 -19
- data/VERSION +1 -1
- data/lib/generators/mapfish/print_controller/USAGE +12 -0
- data/lib/generators/mapfish/print_controller/print_controller_generator.rb +25 -0
- data/{generators → lib/generators/mapfish}/print_controller/templates/config.yaml +0 -0
- data/{generators → lib/generators/mapfish}/print_controller/templates/controller.rb +2 -1
- data/lib/generators/mapfish/resource/USAGE +21 -0
- data/lib/generators/mapfish/resource/resource_generator.rb +22 -0
- data/{generators/mapfish_resource → lib/generators/mapfish/resource}/templates/controller.rb +9 -9
- data/lib/print.rb +1 -7
- data/mapfish.gemspec +11 -16
- metadata +16 -16
- data/generators/mapfish_resource/USAGE +0 -28
- data/generators/mapfish_resource/mapfish_resource_generator.rb +0 -88
- data/generators/mapfish_resource/templates/functional_test.rb +0 -46
- data/generators/mapfish_resource/templates/helper.rb +0 -2
- data/generators/print_controller/USAGE +0 -16
- data/generators/print_controller/print_controller_generator.rb +0 -39
- data/generators/print_controller/templates/functional_test.rb +0 -8
- data/generators/print_controller/templates/helper.rb +0 -2
- data/generators/print_controller/templates/helper_test.rb +0 -4
data/README
CHANGED
@@ -12,25 +12,32 @@ Create a MapFish project
|
|
12
12
|
|
13
13
|
Create a new Rails project::
|
14
14
|
|
15
|
-
rails --database=postgresql
|
15
|
+
rails new MyMapFishProject --database=postgresql
|
16
16
|
cd MyMapFishProject
|
17
17
|
|
18
|
-
|
18
|
+
Rails 3: Add the mapfish plugin to your Gemfile::
|
19
19
|
|
20
|
-
|
20
|
+
gem 'mapfish'
|
21
21
|
|
22
|
-
|
22
|
+
Then from your project’s RAILS_ROOT, run:
|
23
23
|
|
24
|
-
|
24
|
+
bundle install
|
25
|
+
|
26
|
+
Rails 2: Add the mapfish plugin to your config/environment.rb::
|
27
|
+
|
28
|
+
config.gem 'mapfish'
|
29
|
+
|
30
|
+
Then from your project’s RAILS_ROOT, run:
|
25
31
|
|
26
|
-
|
32
|
+
rake gems:install
|
27
33
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
+
It is also possible to install mapfish as a plugin::
|
35
|
+
|
36
|
+
script/plugin install http://www.mapfish.org/svn/mapfish/implementations/rails-plugin/mapfish/trunk
|
37
|
+
|
38
|
+
Install the latest version of the Mapfish client libraries::
|
39
|
+
|
40
|
+
rake mapfish:install_client
|
34
41
|
|
35
42
|
Set up the PostGIS database
|
36
43
|
---------------------------
|
@@ -66,18 +73,18 @@ You now need to create layers. In effect, a layer corresponds to a PostGIS table
|
|
66
73
|
|
67
74
|
Create a resource (model and controller)::
|
68
75
|
|
69
|
-
|
76
|
+
rails generate mapfish:resource WeatherStation name:string geom:point --skip-timestamps --skip-fixture
|
70
77
|
rake db:migrate
|
71
78
|
|
72
79
|
Import some data::
|
73
80
|
|
74
|
-
|
81
|
+
rails runner "Geonames::Weather.weather(:north => 44.1, :south => -9.9, :east => -22.4, :west => 55.2).each { |st| WeatherStation.create(:name => st.stationName, :geom => Point.from_x_y(st.lng, st.lat)) }"
|
75
82
|
|
76
83
|
(needs lib/geonames.rb from http://github.com/pka/map_layers/tree in lib/)
|
77
84
|
|
78
85
|
Create a resource for an existing table::
|
79
86
|
|
80
|
-
|
87
|
+
rails generate mapfish:resource Country --skip-migration --skip-fixture
|
81
88
|
|
82
89
|
Insert table name and custom id in ``app/models/country.rb``::
|
83
90
|
|
@@ -92,7 +99,7 @@ Starting the web server
|
|
92
99
|
|
93
100
|
You should be all set now. Try starting the web server::
|
94
101
|
|
95
|
-
|
102
|
+
rails server
|
96
103
|
|
97
104
|
and checkout ``http://localhost:3000/countries?maxfeatures=10``
|
98
105
|
|
@@ -122,11 +129,11 @@ Using the print module
|
|
122
129
|
|
123
130
|
The Rails MapFish plugin can generate a controller for the `MapFish print protocol <http://trac.mapfish.org/trac/mapfish/wiki/PrintModuleDoc#Protocol>`_, to produce PDF outputs of your maps. (see `MapFish PrintModuleDoc <http://trac.mapfish.org/trac/mapfish/wiki/PrintModuleDoc>`_)::
|
124
131
|
|
125
|
-
|
132
|
+
rails generate mapfish:print_controller Print
|
126
133
|
|
127
134
|
You'll need to have `Sun's JRE <http://www.java.com/download/>`_ installed to make this working.
|
128
135
|
|
129
|
-
* The print module should be ready & responding to /print/info to get print configuration.
|
136
|
+
* The print module should be ready & responding to /print/info.json to get print configuration.
|
130
137
|
Don't forget to adapt config/print.yaml (see `configuration <http://trac.mapfish.org/trac/mapfish/wiki/PrintModuleServer>`_. For instance, you should at least allow the print service to access the WMS services you're using.
|
131
138
|
If you're getting errors, check your log file to get debug information.
|
132
139
|
|
@@ -138,4 +145,4 @@ License
|
|
138
145
|
|
139
146
|
The Mapfish server plugin for Rails is released under the LGPL license.
|
140
147
|
|
141
|
-
*Copyright (c) 2008 Pirmin Kalberer, Sourcepole AG*
|
148
|
+
*Copyright (c) 2008-2010 Pirmin Kalberer, Sourcepole AG*
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.3.
|
1
|
+
1.3.4
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Description:
|
2
|
+
Stubs out a new MapFish controller and its views. Pass the controller name,
|
3
|
+
either CamelCased or under_scored.
|
4
|
+
|
5
|
+
To create a controller within a module, specify the controller name as a
|
6
|
+
path like 'parent_module/controller_name'.
|
7
|
+
|
8
|
+
This generates a controller class in app/controllers, a sample configuration
|
9
|
+
config/print.yaml and invokes helper and test framework generators.
|
10
|
+
|
11
|
+
Example:
|
12
|
+
`rails generate mapfish:print_controller Print`
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Mapfish
|
2
|
+
class PrintControllerGenerator < Rails::Generators::NamedBase
|
3
|
+
check_class_collision :suffix => "Controller"
|
4
|
+
|
5
|
+
def self.source_root
|
6
|
+
@source_root ||= File.expand_path('../templates', __FILE__)
|
7
|
+
end
|
8
|
+
|
9
|
+
def create_controller_files
|
10
|
+
template 'controller.rb', File.join('app/controllers', class_path, "#{file_name}_controller.rb")
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_config_files
|
14
|
+
template 'config.yaml', File.join('config', class_path, "print.yaml")
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_routes
|
18
|
+
route %{match '#{file_name}/info.:format' => "#{file_name}#info", :via => :get}
|
19
|
+
route %{match '#{file_name}/create.:format' => "#{file_name}#create", :via => :post}
|
20
|
+
route %{match '#{file_name}/:id.:format' => "#{file_name}#show", :via => :get}
|
21
|
+
end
|
22
|
+
|
23
|
+
hook_for :helper, :as => :controller, :in => :rails
|
24
|
+
end
|
25
|
+
end
|
File without changes
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Description:
|
2
|
+
Scaffolds an entire MapFish resource, from model and migration to controller,
|
3
|
+
along with a full test suite.
|
4
|
+
|
5
|
+
Pass the singular model name, either CamelCased or under_scored, as the
|
6
|
+
first argument, and an optional list of attribute pairs.
|
7
|
+
|
8
|
+
Attribute pairs are field:type arguments specifying the
|
9
|
+
model's attributes. Timestamps are added by default, so you don't have to
|
10
|
+
specify them by hand as 'created_at:datetime updated_at:datetime'.
|
11
|
+
|
12
|
+
You don't have to think up every attribute up front, but it helps to
|
13
|
+
sketch out a few so you can start working with the model immediately.
|
14
|
+
|
15
|
+
This generator invokes your configured ORM and test framework, besides
|
16
|
+
creating helpers and add routes to config/routes.rb.
|
17
|
+
|
18
|
+
Examples:
|
19
|
+
`rails generate mapfish::resource post` # no attributes
|
20
|
+
`rails generate mapfish::resource post title:string body:text published:boolean`
|
21
|
+
`rails generate mapfish::resource weather_station name:string position:point`
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rails/generators/rails/resource/resource_generator'
|
2
|
+
|
3
|
+
module Mapfish
|
4
|
+
class ResourceGenerator < Rails::Generators::ResourceGenerator
|
5
|
+
remove_hook_for :resource_controller
|
6
|
+
remove_class_option :actions
|
7
|
+
|
8
|
+
def self.source_root
|
9
|
+
@source_root ||= File.expand_path('../templates', __FILE__)
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_controller_files
|
13
|
+
template 'controller.rb', File.join('app/controllers', class_path, "#{controller_file_name}_controller.rb")
|
14
|
+
end
|
15
|
+
|
16
|
+
# Invoke the helper using the controller name (pluralized)
|
17
|
+
hook_for :helper, :in => :rails, :as => :scaffold do |invoked|
|
18
|
+
invoke invoked, [ controller_name ]
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/{generators/mapfish_resource → lib/generators/mapfish/resource}/templates/controller.rb
RENAMED
@@ -2,16 +2,18 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
2
2
|
|
3
3
|
SRID = <%= class_name %>.geometry_column.srid
|
4
4
|
|
5
|
+
<% unless options[:singleton] -%>
|
5
6
|
# GET /<%= table_name %>
|
6
7
|
def index
|
7
|
-
@<%= table_name %> = <%= class_name %>.
|
8
|
+
@<%= table_name %> = <%= class_name %>.mapfish_filter(params)
|
8
9
|
|
9
10
|
render :json => @<%= table_name %>.to_geojson
|
10
11
|
end
|
12
|
+
<% end -%>
|
11
13
|
|
12
14
|
# GET /<%= table_name %>/1
|
13
15
|
def show
|
14
|
-
@<%= file_name %> = <%= class_name
|
16
|
+
@<%= file_name %> = <%= orm_class.find(class_name, "params[:id]") %>
|
15
17
|
|
16
18
|
render :json => [@<%= file_name %>].to_geojson
|
17
19
|
end
|
@@ -27,10 +29,10 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
27
29
|
|
28
30
|
feature_collection.features.each do |feature|
|
29
31
|
if feature.id.is_a? Integer
|
30
|
-
<%= file_name %> = <%= class_name
|
32
|
+
<%= file_name %> = <%= orm_class.find(class_name, "feature.id") %>
|
31
33
|
end
|
32
34
|
if <%= file_name %>.nil?
|
33
|
-
<%= file_name %> = <%= class_name
|
35
|
+
<%= file_name %> = <%= orm_class.build(class_name) %>
|
34
36
|
end
|
35
37
|
|
36
38
|
if <%= file_name %>.update_attributes_from_feature(feature)
|
@@ -50,7 +52,7 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
50
52
|
end
|
51
53
|
|
52
54
|
if feature.id.is_a? Integer
|
53
|
-
@<%= file_name %> = <%= class_name
|
55
|
+
@<%= file_name %> = <%= orm_class.find(class_name, "feature.id") %>
|
54
56
|
end
|
55
57
|
if @<%= file_name %>.nil?
|
56
58
|
head :not_found
|
@@ -66,10 +68,8 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
66
68
|
|
67
69
|
# DELETE /<%= table_name %>/1
|
68
70
|
def destroy
|
69
|
-
@<%= file_name %> = <%= class_name
|
70
|
-
@<%=
|
71
|
-
|
71
|
+
@<%= file_name %> = <%= orm_class.find(class_name, "params[:id]") %>
|
72
|
+
@<%= orm_instance.destroy %>
|
72
73
|
head :no_content
|
73
74
|
end
|
74
|
-
|
75
75
|
end
|
data/lib/print.rb
CHANGED
@@ -17,6 +17,7 @@
|
|
17
17
|
# along with MapFish Server. If not, see <http://www.gnu.org/licenses/>.
|
18
18
|
#
|
19
19
|
|
20
|
+
require 'mapfish'
|
20
21
|
require 'popen4'
|
21
22
|
require 'tmpdir'
|
22
23
|
|
@@ -30,13 +31,6 @@ module MapFish
|
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
|
-
# Used to add the needed routes for the print module
|
34
|
-
def self.add_routes(map, controller = 'print', base = 'print')
|
35
|
-
map.connect(base+'/info.:format', :controller=>controller, :action=>'info', :method=>:get)
|
36
|
-
map.connect(base+'/create.:format', :controller=>controller, :action=>'create', :method=>:post)
|
37
|
-
map.connect(base+'/:id.:format', :controller=>controller, :action=>'show', :method=>:get)
|
38
|
-
end
|
39
|
-
|
40
34
|
# To have a controller for the print module, just mix-in this module to
|
41
35
|
# one of your controllers. This controller must have an attribute @configFile.
|
42
36
|
# For example:
|
data/mapfish.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mapfish}
|
8
|
-
s.version = "1.3.
|
8
|
+
s.version = "1.3.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Pirmin Kalberer"]
|
12
|
-
s.date = %q{2010-06-
|
12
|
+
s.date = %q{2010-06-19}
|
13
13
|
s.description = %q{MapFish is a flexible and complete framework for building rich web-mapping applications. Homepage: mapfish.org}
|
14
14
|
s.email = %q{pka@sourcepole.ch}
|
15
15
|
s.files = [
|
@@ -17,20 +17,15 @@ Gem::Specification.new do |s|
|
|
17
17
|
"README",
|
18
18
|
"Rakefile",
|
19
19
|
"VERSION",
|
20
|
-
"generators/mapfish_resource/USAGE",
|
21
|
-
"generators/mapfish_resource/mapfish_resource_generator.rb",
|
22
|
-
"generators/mapfish_resource/templates/controller.rb",
|
23
|
-
"generators/mapfish_resource/templates/functional_test.rb",
|
24
|
-
"generators/mapfish_resource/templates/helper.rb",
|
25
|
-
"generators/print_controller/USAGE",
|
26
|
-
"generators/print_controller/print_controller_generator.rb",
|
27
|
-
"generators/print_controller/templates/config.yaml",
|
28
|
-
"generators/print_controller/templates/controller.rb",
|
29
|
-
"generators/print_controller/templates/functional_test.rb",
|
30
|
-
"generators/print_controller/templates/helper.rb",
|
31
|
-
"generators/print_controller/templates/helper_test.rb",
|
32
20
|
"init.rb",
|
33
21
|
"install.rb",
|
22
|
+
"lib/generators/mapfish/print_controller/USAGE",
|
23
|
+
"lib/generators/mapfish/print_controller/print_controller_generator.rb",
|
24
|
+
"lib/generators/mapfish/print_controller/templates/config.yaml",
|
25
|
+
"lib/generators/mapfish/print_controller/templates/controller.rb",
|
26
|
+
"lib/generators/mapfish/resource/USAGE",
|
27
|
+
"lib/generators/mapfish/resource/resource_generator.rb",
|
28
|
+
"lib/generators/mapfish/resource/templates/controller.rb",
|
34
29
|
"lib/geojson.rb",
|
35
30
|
"lib/mapfish.rb",
|
36
31
|
"lib/mapfish_core_extensions/active_record/base.rb",
|
@@ -45,14 +40,14 @@ Gem::Specification.new do |s|
|
|
45
40
|
s.homepage = %q{http://mapfish.org/doc/implementations/rails.html}
|
46
41
|
s.rdoc_options = ["--charset=UTF-8"]
|
47
42
|
s.require_paths = ["lib"]
|
48
|
-
s.rubygems_version = %q{1.3.
|
43
|
+
s.rubygems_version = %q{1.3.7}
|
49
44
|
s.summary = %q{Mapfish server plugin for Ruby on Rails}
|
50
45
|
|
51
46
|
if s.respond_to? :specification_version then
|
52
47
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
53
48
|
s.specification_version = 3
|
54
49
|
|
55
|
-
if Gem::Version.new(Gem::
|
50
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
56
51
|
s.add_runtime_dependency(%q<spatial_adapter>, [">= 0"])
|
57
52
|
s.add_runtime_dependency(%q<GeoRuby>, [">= 0"])
|
58
53
|
s.add_runtime_dependency(%q<POpen4>, [">= 0.1.4"])
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 1.3.
|
8
|
+
- 4
|
9
|
+
version: 1.3.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Pirmin Kalberer
|
@@ -14,13 +14,14 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-06-
|
17
|
+
date: 2010-06-19 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: spatial_adapter
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
24
25
|
requirements:
|
25
26
|
- - ">="
|
26
27
|
- !ruby/object:Gem::Version
|
@@ -33,6 +34,7 @@ dependencies:
|
|
33
34
|
name: GeoRuby
|
34
35
|
prerelease: false
|
35
36
|
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
36
38
|
requirements:
|
37
39
|
- - ">="
|
38
40
|
- !ruby/object:Gem::Version
|
@@ -45,6 +47,7 @@ dependencies:
|
|
45
47
|
name: POpen4
|
46
48
|
prerelease: false
|
47
49
|
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
48
51
|
requirements:
|
49
52
|
- - ">="
|
50
53
|
- !ruby/object:Gem::Version
|
@@ -68,20 +71,15 @@ files:
|
|
68
71
|
- README
|
69
72
|
- Rakefile
|
70
73
|
- VERSION
|
71
|
-
- generators/mapfish_resource/USAGE
|
72
|
-
- generators/mapfish_resource/mapfish_resource_generator.rb
|
73
|
-
- generators/mapfish_resource/templates/controller.rb
|
74
|
-
- generators/mapfish_resource/templates/functional_test.rb
|
75
|
-
- generators/mapfish_resource/templates/helper.rb
|
76
|
-
- generators/print_controller/USAGE
|
77
|
-
- generators/print_controller/print_controller_generator.rb
|
78
|
-
- generators/print_controller/templates/config.yaml
|
79
|
-
- generators/print_controller/templates/controller.rb
|
80
|
-
- generators/print_controller/templates/functional_test.rb
|
81
|
-
- generators/print_controller/templates/helper.rb
|
82
|
-
- generators/print_controller/templates/helper_test.rb
|
83
74
|
- init.rb
|
84
75
|
- install.rb
|
76
|
+
- lib/generators/mapfish/print_controller/USAGE
|
77
|
+
- lib/generators/mapfish/print_controller/print_controller_generator.rb
|
78
|
+
- lib/generators/mapfish/print_controller/templates/config.yaml
|
79
|
+
- lib/generators/mapfish/print_controller/templates/controller.rb
|
80
|
+
- lib/generators/mapfish/resource/USAGE
|
81
|
+
- lib/generators/mapfish/resource/resource_generator.rb
|
82
|
+
- lib/generators/mapfish/resource/templates/controller.rb
|
85
83
|
- lib/geojson.rb
|
86
84
|
- lib/mapfish.rb
|
87
85
|
- lib/mapfish_core_extensions/active_record/base.rb
|
@@ -102,6 +100,7 @@ rdoc_options:
|
|
102
100
|
require_paths:
|
103
101
|
- lib
|
104
102
|
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
105
104
|
requirements:
|
106
105
|
- - ">="
|
107
106
|
- !ruby/object:Gem::Version
|
@@ -109,6 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
108
|
- 0
|
110
109
|
version: "0"
|
111
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
112
|
requirements:
|
113
113
|
- - ">="
|
114
114
|
- !ruby/object:Gem::Version
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
requirements: []
|
119
119
|
|
120
120
|
rubyforge_project:
|
121
|
-
rubygems_version: 1.3.
|
121
|
+
rubygems_version: 1.3.7
|
122
122
|
signing_key:
|
123
123
|
specification_version: 3
|
124
124
|
summary: Mapfish server plugin for Ruby on Rails
|
@@ -1,28 +0,0 @@
|
|
1
|
-
Description:
|
2
|
-
Scaffolds an entire MapFish resource, from model and migration to controller,
|
3
|
-
along with a full test suite.
|
4
|
-
|
5
|
-
Pass the name of the model (in singular form), either CamelCased or
|
6
|
-
under_scored, as the first argument, and an optional list of attribute
|
7
|
-
pairs.
|
8
|
-
|
9
|
-
Attribute pairs are column_name:sql_type arguments specifying the
|
10
|
-
model's attributes. Timestamps are added by default, so you don't have to
|
11
|
-
specify them by hand as 'created_at:datetime updated_at:datetime'.
|
12
|
-
|
13
|
-
You don't have to think up every attribute up front, but it helps to
|
14
|
-
sketch out a few so you can start working with the resource immediately.
|
15
|
-
|
16
|
-
For example, 'mapfish_resource post title:string body:text published:boolean'
|
17
|
-
gives you a model with those three attributes, a controller that handles
|
18
|
-
the create/show/update/destroy, forms to create and edit your posts, and
|
19
|
-
an index that lists them all, as well as a map.resources :posts
|
20
|
-
declaration in config/routes.rb.
|
21
|
-
|
22
|
-
If you want to remove all the generated files, run
|
23
|
-
'script/destroy mapfish_resource ModelName'.
|
24
|
-
|
25
|
-
Examples:
|
26
|
-
`./script/generate mapfish_resource post`
|
27
|
-
`./script/generate mapfish_resource post title:string body:text published:boolean`
|
28
|
-
`./script/generate mapfish_resource WeatherStation name:string position:point`
|
@@ -1,88 +0,0 @@
|
|
1
|
-
class MapfishResourceGenerator < Rails::Generator::NamedBase
|
2
|
-
default_options :skip_timestamps => false, :skip_migration => false, :force_plural => false
|
3
|
-
|
4
|
-
attr_reader :controller_name,
|
5
|
-
:controller_class_path,
|
6
|
-
:controller_file_path,
|
7
|
-
:controller_class_nesting,
|
8
|
-
:controller_class_nesting_depth,
|
9
|
-
:controller_class_name,
|
10
|
-
:controller_underscore_name,
|
11
|
-
:controller_singular_name,
|
12
|
-
:controller_plural_name
|
13
|
-
alias_method :controller_file_name, :controller_underscore_name
|
14
|
-
alias_method :controller_table_name, :controller_plural_name
|
15
|
-
|
16
|
-
def initialize(runtime_args, runtime_options = {})
|
17
|
-
super
|
18
|
-
|
19
|
-
if @name == @name.pluralize && !options[:force_plural]
|
20
|
-
logger.warning "Plural version of the model detected, using singularized version. Override with --force-plural."
|
21
|
-
@name = @name.singularize
|
22
|
-
end
|
23
|
-
|
24
|
-
@controller_name = @name.pluralize
|
25
|
-
|
26
|
-
base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
|
27
|
-
@controller_class_name_without_nesting, @controller_underscore_name, @controller_plural_name = inflect_names(base_name)
|
28
|
-
@controller_singular_name=base_name.singularize
|
29
|
-
if @controller_class_nesting.empty?
|
30
|
-
@controller_class_name = @controller_class_name_without_nesting
|
31
|
-
else
|
32
|
-
@controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def manifest
|
37
|
-
record do |m|
|
38
|
-
# Check for class naming collisions.
|
39
|
-
m.class_collisions("#{controller_class_name}Controller", "#{controller_class_name}Helper")
|
40
|
-
m.class_collisions(class_name)
|
41
|
-
|
42
|
-
# Controller, helper, views, test and stylesheets directories.
|
43
|
-
m.directory(File.join('app/models', class_path))
|
44
|
-
m.directory(File.join('app/controllers', controller_class_path))
|
45
|
-
m.directory(File.join('app/helpers', controller_class_path))
|
46
|
-
m.directory(File.join('test/functional', controller_class_path))
|
47
|
-
m.directory(File.join('test/unit', class_path))
|
48
|
-
m.directory(File.join('test/unit/helpers', class_path))
|
49
|
-
|
50
|
-
m.template(
|
51
|
-
'controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
|
52
|
-
)
|
53
|
-
|
54
|
-
m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb"))
|
55
|
-
m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb"))
|
56
|
-
#m.template('helper_test.rb', File.join('test/unit/helpers', controller_class_path, "#{controller_file_name}_helper_test.rb"))
|
57
|
-
|
58
|
-
m.route_resources controller_file_name
|
59
|
-
|
60
|
-
m.dependency 'model', [name] + @args, :collision => :skip
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
protected
|
65
|
-
# Override with your own usage banner.
|
66
|
-
def banner
|
67
|
-
"Usage: #{$0} mapfish_resource ModelName [field:type, field:type]"
|
68
|
-
end
|
69
|
-
|
70
|
-
def add_options!(opt)
|
71
|
-
opt.separator ''
|
72
|
-
opt.separator 'Options:'
|
73
|
-
opt.on("--skip-timestamps",
|
74
|
-
"Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v }
|
75
|
-
opt.on("--skip-migration",
|
76
|
-
"Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
|
77
|
-
opt.on("--force-plural",
|
78
|
-
"Forces the generation of a plural ModelName") { |v| options[:force_plural] = v }
|
79
|
-
end
|
80
|
-
|
81
|
-
def scaffold_views
|
82
|
-
%w[ index show new edit ]
|
83
|
-
end
|
84
|
-
|
85
|
-
def model_name
|
86
|
-
class_name.demodulize
|
87
|
-
end
|
88
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
|
4
|
-
|
5
|
-
test "should get index" do
|
6
|
-
get :index
|
7
|
-
assert_response :success
|
8
|
-
assert_not_nil assigns(:<%= table_name %>)
|
9
|
-
end
|
10
|
-
|
11
|
-
test "should get new" do
|
12
|
-
get :new
|
13
|
-
assert_response :success
|
14
|
-
end
|
15
|
-
|
16
|
-
test "should create <%= file_name %>" do
|
17
|
-
assert_difference('<%= class_name %>.count') do
|
18
|
-
post :create, :<%= file_name %> => { }
|
19
|
-
end
|
20
|
-
|
21
|
-
assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
|
22
|
-
end
|
23
|
-
|
24
|
-
test "should show <%= file_name %>" do
|
25
|
-
get :show, :id => <%= table_name %>(:one).to_param
|
26
|
-
assert_response :success
|
27
|
-
end
|
28
|
-
|
29
|
-
test "should get edit" do
|
30
|
-
get :edit, :id => <%= table_name %>(:one).to_param
|
31
|
-
assert_response :success
|
32
|
-
end
|
33
|
-
|
34
|
-
test "should update <%= file_name %>" do
|
35
|
-
put :update, :id => <%= table_name %>(:one).to_param, :<%= file_name %> => { }
|
36
|
-
assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
|
37
|
-
end
|
38
|
-
|
39
|
-
test "should destroy <%= file_name %>" do
|
40
|
-
assert_difference('<%= class_name %>.count', -1) do
|
41
|
-
delete :destroy, :id => <%= table_name %>(:one).to_param
|
42
|
-
end
|
43
|
-
|
44
|
-
assert_redirected_to <%= table_name %>_path
|
45
|
-
end
|
46
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
Description:
|
2
|
-
Stubs out a new MapFish print controller. Pass the controller name, either
|
3
|
-
CamelCased or under_scored.
|
4
|
-
|
5
|
-
To create a controller within a module, specify the controller name as a
|
6
|
-
path like 'parent_module/controller_name'.
|
7
|
-
|
8
|
-
This generates a controller class in app/controllers, a sample configuration
|
9
|
-
config/print.yaml, a helper class in app/helpers, a functional
|
10
|
-
test suite in test/functional and a helper test suite in test/unit/helpers.
|
11
|
-
|
12
|
-
Example:
|
13
|
-
`./script/generate controller Print
|
14
|
-
|
15
|
-
Modules Example:
|
16
|
-
`./script/generate controller 'admin/print'`
|
@@ -1,39 +0,0 @@
|
|
1
|
-
class PrintControllerGenerator < Rails::Generator::NamedBase
|
2
|
-
def manifest
|
3
|
-
record do |m|
|
4
|
-
# Check for class naming collisions.
|
5
|
-
m.class_collisions "#{class_name}Controller", "#{class_name}ControllerTest", "#{class_name}Helper", "#{class_name}HelperTest"
|
6
|
-
|
7
|
-
# Controller, helper, views, and test directories.
|
8
|
-
m.directory File.join('app/controllers', class_path)
|
9
|
-
m.directory File.join('app/helpers', class_path)
|
10
|
-
m.directory File.join('test/functional', class_path)
|
11
|
-
m.directory File.join('test/unit/helpers', class_path)
|
12
|
-
m.directory File.join('config', class_path)
|
13
|
-
|
14
|
-
# Controller class, functional test, and helper class.
|
15
|
-
m.template 'controller.rb',
|
16
|
-
File.join('app/controllers',
|
17
|
-
class_path,
|
18
|
-
"#{file_name}_controller.rb")
|
19
|
-
|
20
|
-
m.template 'functional_test.rb',
|
21
|
-
File.join('test/functional',
|
22
|
-
class_path,
|
23
|
-
"#{file_name}_controller_test.rb")
|
24
|
-
|
25
|
-
m.template 'helper.rb',
|
26
|
-
File.join('app/helpers',
|
27
|
-
class_path,
|
28
|
-
"#{file_name}_helper.rb")
|
29
|
-
|
30
|
-
m.template 'helper_test.rb',
|
31
|
-
File.join('test/unit/helpers',
|
32
|
-
class_path,
|
33
|
-
"#{file_name}_helper_test.rb")
|
34
|
-
|
35
|
-
# Config file
|
36
|
-
m.template 'config.yaml', File.join('config', "print.yaml")
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|