starter-template_generator 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/Manifest +32 -0
- data/README.markdown +76 -0
- data/Rakefile +26 -0
- data/TODO +8 -0
- data/VERSION.yml +4 -0
- data/rails_generators/shoulda_model/USAGE +27 -0
- data/rails_generators/shoulda_model/shoulda_model_generator.rb +49 -0
- data/rails_generators/shoulda_model/templates/factory.rb +5 -0
- data/rails_generators/shoulda_model/templates/fixtures.yml +19 -0
- data/rails_generators/shoulda_model/templates/migration.rb +16 -0
- data/rails_generators/shoulda_model/templates/model.rb +2 -0
- data/rails_generators/shoulda_model/templates/unit_test.rb +7 -0
- data/rails_generators/shoulda_scaffold/USAGE +34 -0
- data/rails_generators/shoulda_scaffold/shoulda_scaffold_generator.rb +160 -0
- data/rails_generators/shoulda_scaffold/templates/blueprint/ie.css +35 -0
- data/rails_generators/shoulda_scaffold/templates/blueprint/print.css +30 -0
- data/rails_generators/shoulda_scaffold/templates/blueprint/screen.css +256 -0
- data/rails_generators/shoulda_scaffold/templates/controller.rb +65 -0
- data/rails_generators/shoulda_scaffold/templates/erb/_form.html.erb +8 -0
- data/rails_generators/shoulda_scaffold/templates/erb/edit.html.erb +12 -0
- data/rails_generators/shoulda_scaffold/templates/erb/index.html.erb +24 -0
- data/rails_generators/shoulda_scaffold/templates/erb/layout.html.erb +22 -0
- data/rails_generators/shoulda_scaffold/templates/erb/new.html.erb +8 -0
- data/rails_generators/shoulda_scaffold/templates/erb/show.html.erb +14 -0
- data/rails_generators/shoulda_scaffold/templates/functional_test/basic.rb +66 -0
- data/rails_generators/shoulda_scaffold/templates/haml/_form.html.haml +7 -0
- data/rails_generators/shoulda_scaffold/templates/haml/edit.html.haml +11 -0
- data/rails_generators/shoulda_scaffold/templates/haml/index.html.haml +23 -0
- data/rails_generators/shoulda_scaffold/templates/haml/new.html.haml +9 -0
- data/rails_generators/shoulda_scaffold/templates/haml/show.html.haml +11 -0
- data/rails_generators/shoulda_scaffold/templates/helper.rb +2 -0
- data/test/fixtures/about_yml_plugins/bad_about_yml/about.yml +1 -0
- data/test/fixtures/about_yml_plugins/bad_about_yml/init.rb +1 -0
- data/test/fixtures/about_yml_plugins/plugin_without_about_yml/init.rb +1 -0
- data/test/fixtures/eager/zoo.rb +3 -0
- data/test/fixtures/eager/zoo/reptile_house.rb +2 -0
- data/test/fixtures/environment_with_constant.rb +1 -0
- data/test/fixtures/lib/generators/missing_class/missing_class_generator.rb +0 -0
- data/test/fixtures/lib/generators/working/working_generator.rb +2 -0
- data/test/fixtures/plugins/alternate/a/generators/a_generator/a_generator.rb +4 -0
- data/test/fixtures/plugins/default/gemlike/init.rb +1 -0
- data/test/fixtures/plugins/default/gemlike/lib/gemlike.rb +2 -0
- data/test/fixtures/plugins/default/gemlike/rails/init.rb +7 -0
- data/test/fixtures/plugins/default/plugin_with_no_lib_dir/init.rb +0 -0
- data/test/fixtures/plugins/default/stubby/about.yml +2 -0
- data/test/fixtures/plugins/default/stubby/generators/stubby_generator/stubby_generator.rb +4 -0
- data/test/fixtures/plugins/default/stubby/init.rb +7 -0
- data/test/fixtures/plugins/default/stubby/lib/stubby_mixin.rb +2 -0
- data/test/rails_generators/shoulda_model_generator_test.rb +39 -0
- data/test/shoulda_macros/generator_macros.rb +36 -0
- data/test/stolen_from_railties.rb +288 -0
- data/test/test_helper.rb +41 -0
- metadata +116 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Josh Nichols
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
rails_generators/shoulda_model/shoulda_model_generator.rb
|
2
|
+
rails_generators/shoulda_model/templates/factory.rb
|
3
|
+
rails_generators/shoulda_model/templates/fixtures.yml
|
4
|
+
rails_generators/shoulda_model/templates/migration.rb
|
5
|
+
rails_generators/shoulda_model/templates/model.rb
|
6
|
+
rails_generators/shoulda_model/templates/unit_test.rb
|
7
|
+
rails_generators/shoulda_model/USAGE
|
8
|
+
rails_generators/shoulda_scaffold/shoulda_scaffold_generator.rb
|
9
|
+
rails_generators/shoulda_scaffold/templates/blueprint/ie.css
|
10
|
+
rails_generators/shoulda_scaffold/templates/blueprint/print.css
|
11
|
+
rails_generators/shoulda_scaffold/templates/blueprint/screen.css
|
12
|
+
rails_generators/shoulda_scaffold/templates/controller.rb
|
13
|
+
rails_generators/shoulda_scaffold/templates/erb/_form.html.erb
|
14
|
+
rails_generators/shoulda_scaffold/templates/erb/edit.html.erb
|
15
|
+
rails_generators/shoulda_scaffold/templates/erb/index.html.erb
|
16
|
+
rails_generators/shoulda_scaffold/templates/erb/layout.html.erb
|
17
|
+
rails_generators/shoulda_scaffold/templates/erb/new.html.erb
|
18
|
+
rails_generators/shoulda_scaffold/templates/erb/show.html.erb
|
19
|
+
rails_generators/shoulda_scaffold/templates/functional_test/basic.rb
|
20
|
+
rails_generators/shoulda_scaffold/templates/functional_test/should_be_restful.rb
|
21
|
+
rails_generators/shoulda_scaffold/templates/haml/_form.html.haml
|
22
|
+
rails_generators/shoulda_scaffold/templates/haml/edit.html.haml
|
23
|
+
rails_generators/shoulda_scaffold/templates/haml/index.html.haml
|
24
|
+
rails_generators/shoulda_scaffold/templates/haml/layout.html.haml
|
25
|
+
rails_generators/shoulda_scaffold/templates/haml/new.html.haml
|
26
|
+
rails_generators/shoulda_scaffold/templates/haml/show.html.haml
|
27
|
+
rails_generators/shoulda_scaffold/templates/helper.rb
|
28
|
+
rails_generators/shoulda_scaffold/USAGE
|
29
|
+
Rakefile
|
30
|
+
README.markdown
|
31
|
+
shoulda_generator.gemspec
|
32
|
+
Manifest
|
data/README.markdown
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# Shoulda generators
|
2
|
+
|
3
|
+
One night at a Boston Ruby hackfest, I finally got sick of using the Rails default generators, and then having to twiddle them to meet my needs and tastes. This includes using things like:
|
4
|
+
|
5
|
+
* [shoulda](http://thoughtbot.com/projects/shoulda)
|
6
|
+
* [factory\_girl](http://github.com/thoughtbot/factory_girl)
|
7
|
+
* [haml](http://haml.hamptoncatlin.com/)
|
8
|
+
* [blueprint](http://code.google.com/p/blueprintcss/)
|
9
|
+
|
10
|
+
The next morning, I was struck awake at 5am with the inspiration to start implementing it. shoulda\_generator is the result of this effort.
|
11
|
+
|
12
|
+
## What you get
|
13
|
+
|
14
|
+
### shoulda\_model
|
15
|
+
|
16
|
+
* A new model
|
17
|
+
* A migration for the model
|
18
|
+
* Skip using --skip-migration
|
19
|
+
* A factory defined with [factory_girl](http://github.com/thoughtbot/factory_girl)
|
20
|
+
* Skip using --skip-factory
|
21
|
+
* A [shoulda](http://thoughtbot.com/projects/shoulda) unit test with a few simple 'should's
|
22
|
+
|
23
|
+
#### Prereqs:
|
24
|
+
|
25
|
+
* [shoulda](http://thoughtbot.com/projects/shoulda) installed as a plugin
|
26
|
+
* [factory\_girl](http://github.com/thoughtbot/factory_girl) gem installed
|
27
|
+
|
28
|
+
### shoulda\_scaffold
|
29
|
+
|
30
|
+
* Everything included in shoulda_model
|
31
|
+
* A controller (sans unnecessary comments)
|
32
|
+
* Choice of [haml](http://haml.hamptoncatlin.com/) (default) or ERB
|
33
|
+
* Specify which with the --templating option
|
34
|
+
* Simple layout styled with blueprint
|
35
|
+
* Skip using --skip-layout
|
36
|
+
* A helper
|
37
|
+
* A shoulda functional test using factory_girl factory, using should\_be\_restful or not
|
38
|
+
* Specify with --functional-test-style, accepts basic and should\_be\_restful
|
39
|
+
|
40
|
+
#### Prereqs:
|
41
|
+
|
42
|
+
* [shoulda](http://thoughtbot.com/projects/shoulda) installed as a plugin
|
43
|
+
* [factory\_girl](http://github.com/thoughtbot/factory_girl) gem installed
|
44
|
+
* [haml](http://haml.hamptoncatlin.com/) gem installed on the system, and the project has been hamlified using `haml --rails`
|
45
|
+
|
46
|
+
## Getting it
|
47
|
+
|
48
|
+
shoulda\_generator is available as a gem via [GitHub](http://github.com). If you haven't done so already, you need to setup GitHub as a gem source:
|
49
|
+
|
50
|
+
$ gem sources -a http://gems.github.com
|
51
|
+
|
52
|
+
Now you can install it:
|
53
|
+
|
54
|
+
$ sudo gem install technicalpickles-shoulda_generator
|
55
|
+
|
56
|
+
## Example usage
|
57
|
+
|
58
|
+
Usage is the same as the default Rails generators.
|
59
|
+
|
60
|
+
$ script/generate shoulda_model post title:string body:text published:boolean
|
61
|
+
$ script/generate shoulda_scaffold post title:string body:text published:boolean
|
62
|
+
|
63
|
+
|
64
|
+
## Configuring it
|
65
|
+
|
66
|
+
You can override the default values for templating by placing a .shoulda\_generator file in your home directory.
|
67
|
+
|
68
|
+
Here's an example `.shoulda_generator`:
|
69
|
+
|
70
|
+
:templating: erb # supported options: haml|erb
|
71
|
+
|
72
|
+
## Developing it
|
73
|
+
|
74
|
+
Source is hosted on GitHub: [http://github.com/technicalpickles/shoulda_generator/tree/master](http://github.com/technicalpickles/shoulda_generator/tree/master)
|
75
|
+
|
76
|
+
You can do the usual fork/commit cycle until you have something ready to share. Send pull requests my way.
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |s|
|
7
|
+
s.name = "shoulda_generator"
|
8
|
+
s.summary = "Generators which create tests using shoulda"
|
9
|
+
s.email = "josh@technicalpickles.com"
|
10
|
+
s.homepage = "http://github.com/technicalpickles/shoulda_generator"
|
11
|
+
s.description = "Generators which create tests using shoulda"
|
12
|
+
s.authors = ["Josh Nichols"]
|
13
|
+
s.files = FileList["[A-Z]*", "{rails_generators,lib,test}/**/*"]
|
14
|
+
end
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
17
|
+
end
|
18
|
+
|
19
|
+
Rake::TestTask.new do |t|
|
20
|
+
t.libs << 'lib'
|
21
|
+
t.pattern = 'test/**/*_test.rb'
|
22
|
+
t.verbose = false
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'Test by default'
|
26
|
+
task :default => :test
|
data/TODO
ADDED
data/VERSION.yml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
Description:
|
2
|
+
Stubs out a new model. Pass the model name, either CamelCased or
|
3
|
+
under_scored, and an optional list of attribute pairs as arguments.
|
4
|
+
|
5
|
+
Attribute pairs are column_name:sql_type arguments specifying the
|
6
|
+
model's attributes. Timestamps are added by default, so you don't have to
|
7
|
+
specify them by hand as 'created_at:datetime updated_at:datetime'.
|
8
|
+
|
9
|
+
You don't have to think up every attribute up front, but it helps to
|
10
|
+
sketch out a few so you can start working with the model immediately.
|
11
|
+
|
12
|
+
This generates a model class in app/models, a unit test in test/unit,
|
13
|
+
a test fixture in test/fixtures/singular_name.yml, and a migration in
|
14
|
+
db/migrate.
|
15
|
+
|
16
|
+
Examples:
|
17
|
+
`./script/generate shoulda_model account`
|
18
|
+
|
19
|
+
creates an Account model, test, factory, and migration:
|
20
|
+
Model: app/models/account.rb
|
21
|
+
Test: test/unit/account_test.rb
|
22
|
+
Factory: test/factories/account_factory.rb
|
23
|
+
Migration: db/migrate/XXX_add_accounts.rb
|
24
|
+
|
25
|
+
`./script/generate shoulda_model post title:string body:text published:boolean`
|
26
|
+
|
27
|
+
creates a Post model with a string title, text body, and published flag.
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class ShouldaModelGenerator < Rails::Generator::NamedBase
|
2
|
+
default_options :skip_timestamps => false, :skip_migration => false, :skip_factory => false
|
3
|
+
|
4
|
+
def manifest
|
5
|
+
record do |m|
|
6
|
+
# Check for class naming collisions.
|
7
|
+
m.class_collisions class_path, class_name, "#{class_name}Test"
|
8
|
+
|
9
|
+
# Model, test, and fixture directories.
|
10
|
+
m.directory File.join('app/models', class_path)
|
11
|
+
m.directory File.join('test/unit', class_path)
|
12
|
+
m.directory File.join('test/factories', class_path)
|
13
|
+
|
14
|
+
# Model class, unit test, and fixtures.
|
15
|
+
m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
|
16
|
+
m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb")
|
17
|
+
|
18
|
+
unless options[:skip_factory]
|
19
|
+
m.template 'factory.rb', File.join('test/factories', class_path, "#{file_name}_factory.rb")
|
20
|
+
end
|
21
|
+
|
22
|
+
unless options[:skip_migration]
|
23
|
+
m.migration_template 'migration.rb', 'db/migrate', :assigns => {
|
24
|
+
:migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
|
25
|
+
}, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def factory_line(attribute)
|
31
|
+
"#{file_name}.#{attribute.name} '#{attribute.default}'"
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
def banner
|
36
|
+
"Usage: #{$0} #{spec.name} ModelName [field:type, field:type]"
|
37
|
+
end
|
38
|
+
|
39
|
+
def add_options!(opt)
|
40
|
+
opt.separator ''
|
41
|
+
opt.separator 'Options:'
|
42
|
+
opt.on("--skip-timestamps",
|
43
|
+
"Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v }
|
44
|
+
opt.on("--skip-migration",
|
45
|
+
"Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
|
46
|
+
opt.on("--skip-factory",
|
47
|
+
"Don't generation a fixture file for this model") { |v| options[:skip_factory] = v}
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
2
|
+
|
3
|
+
<% unless attributes.empty? -%>
|
4
|
+
one:
|
5
|
+
<% for attribute in attributes -%>
|
6
|
+
<%= attribute.name %>: <%= attribute.default %>
|
7
|
+
<% end -%>
|
8
|
+
|
9
|
+
two:
|
10
|
+
<% for attribute in attributes -%>
|
11
|
+
<%= attribute.name %>: <%= attribute.default %>
|
12
|
+
<% end -%>
|
13
|
+
<% else -%>
|
14
|
+
# one:
|
15
|
+
# column: value
|
16
|
+
#
|
17
|
+
# two:
|
18
|
+
# column: value
|
19
|
+
<% end -%>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class <%= migration_name %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :<%= table_name %> do |t|
|
4
|
+
<% for attribute in attributes -%>
|
5
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
6
|
+
<% end -%>
|
7
|
+
<% unless options[:skip_timestamps] %>
|
8
|
+
t.timestamps
|
9
|
+
<% end -%>
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
drop_table :<%= table_name %>
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
Description:
|
2
|
+
Scaffolds an entire resource, from model and migration to controller and
|
3
|
+
views, along with a full test suite. The resource is ready to use as a
|
4
|
+
starting point for your restful, resource-oriented application.
|
5
|
+
|
6
|
+
Pass the name of the model, either CamelCased or under_scored, as the first
|
7
|
+
argument, and an optional list of attribute 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, `scaffold 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
|
+
You can override the default values for templating and
|
23
|
+
functional\_test\_style by placing a .shoulda\_generator file in your home
|
24
|
+
directory.
|
25
|
+
|
26
|
+
Here's an example `.shoulda_generator`:
|
27
|
+
|
28
|
+
:templating: erb # supported options: haml|erb
|
29
|
+
:functional_test_syle: basic # supported options: should_be_restful|basic
|
30
|
+
|
31
|
+
Examples:
|
32
|
+
`./script/generate shoulda_scaffold post` # no attributes, view will be anemic
|
33
|
+
`./script/generate shoulda_scaffold post title:string body:text published:boolean`
|
34
|
+
`./script/generate shoulda_scaffold purchase order_id:integer amount:decimal`
|
@@ -0,0 +1,160 @@
|
|
1
|
+
#--
|
2
|
+
# ShouldaScaffoldGeneratorConfig based on rubygems code.
|
3
|
+
# Thank you Chad Fowler, Rich Kilmer, Jim Weirich and others.
|
4
|
+
#++
|
5
|
+
class ShouldaScaffoldGeneratorConfig
|
6
|
+
|
7
|
+
DEFAULT_TEMPLATING = 'haml'
|
8
|
+
|
9
|
+
def initialize()
|
10
|
+
@config = load_file(config_file)
|
11
|
+
|
12
|
+
@templating = @config[:templating] || DEFAULT_TEMPLATING
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :templating
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def load_file(filename)
|
20
|
+
begin
|
21
|
+
YAML.load(File.read(filename)) if filename and File.exist?(filename)
|
22
|
+
rescue ArgumentError
|
23
|
+
warn "Failed to load #{config_file_name}"
|
24
|
+
rescue Errno::EACCES
|
25
|
+
warn "Failed to load #{config_file_name} due to permissions problem."
|
26
|
+
end or {}
|
27
|
+
end
|
28
|
+
|
29
|
+
def config_file
|
30
|
+
File.join(find_home, '.shoulda_generator')
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
34
|
+
# Finds the user's home directory.
|
35
|
+
|
36
|
+
def find_home
|
37
|
+
['HOME', 'USERPROFILE'].each do |homekey|
|
38
|
+
return ENV[homekey] if ENV[homekey]
|
39
|
+
end
|
40
|
+
|
41
|
+
if ENV['HOMEDRIVE'] && ENV['HOMEPATH'] then
|
42
|
+
return "#{ENV['HOMEDRIVE']}:#{ENV['HOMEPATH']}"
|
43
|
+
end
|
44
|
+
|
45
|
+
begin
|
46
|
+
File.expand_path("~")
|
47
|
+
rescue
|
48
|
+
if File::ALT_SEPARATOR then
|
49
|
+
"C:/"
|
50
|
+
else
|
51
|
+
"/"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class ShouldaScaffoldGenerator < Rails::Generator::NamedBase
|
58
|
+
default_options :skip_timestamps => false, :skip_migration => false, :skip_layout => true
|
59
|
+
|
60
|
+
attr_reader :controller_name,
|
61
|
+
:controller_class_path,
|
62
|
+
:controller_file_path,
|
63
|
+
:controller_class_nesting,
|
64
|
+
:controller_class_nesting_depth,
|
65
|
+
:controller_class_name,
|
66
|
+
:controller_underscore_name,
|
67
|
+
:controller_singular_name,
|
68
|
+
:controller_plural_name
|
69
|
+
alias_method :controller_file_name, :controller_underscore_name
|
70
|
+
alias_method :controller_table_name, :controller_plural_name
|
71
|
+
|
72
|
+
def initialize(runtime_args, runtime_options = {})
|
73
|
+
super
|
74
|
+
|
75
|
+
@configuration = ShouldaScaffoldGeneratorConfig.new
|
76
|
+
|
77
|
+
@controller_name = @name.pluralize
|
78
|
+
|
79
|
+
base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
|
80
|
+
@controller_class_name_without_nesting, @controller_underscore_name, @controller_plural_name = inflect_names(base_name)
|
81
|
+
@controller_singular_name=base_name.singularize
|
82
|
+
if @controller_class_nesting.empty?
|
83
|
+
@controller_class_name = @controller_class_name_without_nesting
|
84
|
+
else
|
85
|
+
@controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def manifest
|
90
|
+
record do |m|
|
91
|
+
# Check for class naming collisions.
|
92
|
+
m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
|
93
|
+
m.class_collisions(class_path, "#{class_name}")
|
94
|
+
|
95
|
+
# Controller, helper, views, and test directories.
|
96
|
+
m.directory(File.join('app/models', class_path))
|
97
|
+
m.directory(File.join('app/controllers', controller_class_path))
|
98
|
+
m.directory(File.join('app/helpers', controller_class_path))
|
99
|
+
m.directory(File.join('app/views', controller_class_path, controller_file_name))
|
100
|
+
m.directory(File.join('app/views/layouts', controller_class_path))
|
101
|
+
m.directory(File.join('test/functional', controller_class_path))
|
102
|
+
m.directory(File.join('test/unit', class_path))
|
103
|
+
|
104
|
+
m.directory('public/stylesheets/blueprint')
|
105
|
+
|
106
|
+
for view in scaffold_views
|
107
|
+
m.template(
|
108
|
+
"#{templating}/#{view}.html.#{templating}",
|
109
|
+
File.join('app/views', controller_class_path, controller_file_name, "#{view}.html.#{templating}")
|
110
|
+
)
|
111
|
+
end
|
112
|
+
|
113
|
+
# Layout and stylesheet.
|
114
|
+
m.template("#{templating}/layout.html.#{templating}", File.join('app/views/layouts', controller_class_path, "#{controller_file_name}.html.#{templating}"))
|
115
|
+
|
116
|
+
%w(print screen ie).each do |stylesheet|
|
117
|
+
m.template("blueprint/#{stylesheet}.css", "public/stylesheets/blueprint/#{stylesheet}.css")
|
118
|
+
end
|
119
|
+
|
120
|
+
m.template(
|
121
|
+
'controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
|
122
|
+
)
|
123
|
+
|
124
|
+
m.template("functional_test/basic.rb", File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb"))
|
125
|
+
m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb"))
|
126
|
+
|
127
|
+
m.route_resources controller_file_name
|
128
|
+
|
129
|
+
m.dependency 'shoulda_model', [name] + @args, :collision => :skip
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def templating
|
134
|
+
options[:templating] || @configuration.templating
|
135
|
+
end
|
136
|
+
|
137
|
+
protected
|
138
|
+
# Override with your own usage banner.
|
139
|
+
def banner
|
140
|
+
"Usage: #{$0} scaffold ModelName [field:type, field:type]"
|
141
|
+
end
|
142
|
+
|
143
|
+
def add_options!(opt)
|
144
|
+
opt.separator ''
|
145
|
+
opt.separator 'Options:'
|
146
|
+
opt.on("--skip-timestamps",
|
147
|
+
"Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v }
|
148
|
+
opt.on("--skip-migration",
|
149
|
+
"Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
|
150
|
+
opt.on("--templating [erb|haml]", "Specify the templating to use (haml by default)") { |v| options[:templating] = v }
|
151
|
+
end
|
152
|
+
|
153
|
+
def scaffold_views
|
154
|
+
%w[ index show new edit _form ]
|
155
|
+
end
|
156
|
+
|
157
|
+
def model_name
|
158
|
+
class_name.demodulize
|
159
|
+
end
|
160
|
+
end
|