technicalpickles-shoulda_generator 0.1.2 → 0.2.0
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/LICENSE +20 -0
- data/README.markdown +46 -48
- data/Rakefile +23 -7
- data/TODO +8 -0
- data/VERSION.yml +4 -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 +74 -55
- data/rails_generators/shoulda_model/USAGE +0 -27
- data/rails_generators/shoulda_model/shoulda_model_generator.rb +0 -49
- data/rails_generators/shoulda_model/templates/factory.rb +0 -5
- data/rails_generators/shoulda_model/templates/fixtures.yml +0 -19
- data/rails_generators/shoulda_model/templates/migration.rb +0 -16
- data/rails_generators/shoulda_model/templates/model.rb +0 -2
- data/rails_generators/shoulda_model/templates/unit_test.rb +0 -7
- data/rails_generators/shoulda_scaffold/USAGE +0 -25
- data/rails_generators/shoulda_scaffold/shoulda_scaffold_generator.rb +0 -107
- data/rails_generators/shoulda_scaffold/templates/blueprint/ie.css +0 -22
- data/rails_generators/shoulda_scaffold/templates/blueprint/print.css +0 -29
- data/rails_generators/shoulda_scaffold/templates/blueprint/screen.css +0 -226
- data/rails_generators/shoulda_scaffold/templates/controller.rb +0 -72
- data/rails_generators/shoulda_scaffold/templates/erb/_form.html.erb +0 -8
- data/rails_generators/shoulda_scaffold/templates/erb/edit.html.erb +0 -12
- data/rails_generators/shoulda_scaffold/templates/erb/index.html.erb +0 -22
- data/rails_generators/shoulda_scaffold/templates/erb/layout.html.erb +0 -23
- data/rails_generators/shoulda_scaffold/templates/erb/new.html.erb +0 -8
- data/rails_generators/shoulda_scaffold/templates/erb/show.html.erb +0 -12
- data/rails_generators/shoulda_scaffold/templates/functional_test/basic.rb +0 -66
- data/rails_generators/shoulda_scaffold/templates/functional_test/should_be_restful.rb +0 -13
- data/rails_generators/shoulda_scaffold/templates/haml/_form.html.haml +0 -7
- data/rails_generators/shoulda_scaffold/templates/haml/edit.html.haml +0 -9
- data/rails_generators/shoulda_scaffold/templates/haml/index.html.haml +0 -18
- data/rails_generators/shoulda_scaffold/templates/haml/layout.html.haml +0 -15
- data/rails_generators/shoulda_scaffold/templates/haml/new.html.haml +0 -7
- data/rails_generators/shoulda_scaffold/templates/haml/show.html.haml +0 -10
- data/rails_generators/shoulda_scaffold/templates/helper.rb +0 -2
- data/shoulda_generator.gemspec +0 -32
data/test/test_helper.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'ruby-debug'
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_record'
|
5
|
+
require 'action_controller'
|
6
|
+
require 'action_view'
|
7
|
+
|
8
|
+
require 'shoulda'
|
9
|
+
|
10
|
+
require 'mocha'
|
11
|
+
|
12
|
+
require File.join(File.dirname(__FILE__), 'shoulda_macros', 'generator_macros')
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
require File.join(File.dirname(__FILE__), 'stolen_from_railties')
|
17
|
+
|
18
|
+
unless defined?(RAILS_DEFAULT_LOGGER)
|
19
|
+
@test_log = File.join(RAILS_ROOT, 'test.log')
|
20
|
+
RAILS_DEFAULT_LOGGER = Logger.new(@test_log)
|
21
|
+
end
|
22
|
+
|
23
|
+
Rails::Generator::Base.prepend_sources Rails::Generator::PathSource.new(:shoulda_generator, File.join(File.dirname(__FILE__), "..", "rails_generators"))
|
24
|
+
|
25
|
+
class GeneratorTestCase
|
26
|
+
# Asserts that the given factory was created.
|
27
|
+
def assert_generated_factory_for(name)
|
28
|
+
assert_generated_file "test/factories/#{name.to_s.underscore}_factory.rb"
|
29
|
+
end
|
30
|
+
|
31
|
+
# Asserts that the given factory was NOT created.
|
32
|
+
def deny_generated_factory_for(name)
|
33
|
+
deny_file_exists "test/factories/#{name.to_s.underscore}_factory.rb"
|
34
|
+
end
|
35
|
+
|
36
|
+
# asserts that the given file DOES NOT exists
|
37
|
+
def deny_file_exists(path)
|
38
|
+
assert ! File.exist?("#{RAILS_ROOT}/#{path}"),
|
39
|
+
"The file '#{RAILS_ROOT}/#{path}' should not exist"
|
40
|
+
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: technicalpickles-shoulda_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Nichols
|
@@ -9,69 +9,88 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-10-22 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
name: echoe
|
17
|
-
version_requirement:
|
18
|
-
version_requirements: !ruby/object:Gem::Requirement
|
19
|
-
requirements:
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: "0"
|
23
|
-
version:
|
14
|
+
dependencies: []
|
15
|
+
|
24
16
|
description: Generators which create tests using shoulda
|
25
17
|
email: josh@technicalpickles.com
|
26
18
|
executables: []
|
27
19
|
|
28
20
|
extensions: []
|
29
21
|
|
30
|
-
extra_rdoc_files:
|
31
|
-
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
32
24
|
files:
|
33
|
-
-
|
34
|
-
-
|
35
|
-
- rails_generators/shoulda_model/templates/fixtures.yml
|
36
|
-
- rails_generators/shoulda_model/templates/migration.rb
|
37
|
-
- rails_generators/shoulda_model/templates/model.rb
|
38
|
-
- rails_generators/shoulda_model/templates/unit_test.rb
|
39
|
-
- rails_generators/shoulda_model/USAGE
|
40
|
-
- rails_generators/shoulda_scaffold/shoulda_scaffold_generator.rb
|
41
|
-
- rails_generators/shoulda_scaffold/templates/blueprint/ie.css
|
42
|
-
- rails_generators/shoulda_scaffold/templates/blueprint/print.css
|
43
|
-
- rails_generators/shoulda_scaffold/templates/blueprint/screen.css
|
44
|
-
- rails_generators/shoulda_scaffold/templates/controller.rb
|
45
|
-
- rails_generators/shoulda_scaffold/templates/erb/_form.html.erb
|
46
|
-
- rails_generators/shoulda_scaffold/templates/erb/edit.html.erb
|
47
|
-
- rails_generators/shoulda_scaffold/templates/erb/index.html.erb
|
48
|
-
- rails_generators/shoulda_scaffold/templates/erb/layout.html.erb
|
49
|
-
- rails_generators/shoulda_scaffold/templates/erb/new.html.erb
|
50
|
-
- rails_generators/shoulda_scaffold/templates/erb/show.html.erb
|
51
|
-
- rails_generators/shoulda_scaffold/templates/functional_test/basic.rb
|
52
|
-
- rails_generators/shoulda_scaffold/templates/functional_test/should_be_restful.rb
|
53
|
-
- rails_generators/shoulda_scaffold/templates/haml/_form.html.haml
|
54
|
-
- rails_generators/shoulda_scaffold/templates/haml/edit.html.haml
|
55
|
-
- rails_generators/shoulda_scaffold/templates/haml/index.html.haml
|
56
|
-
- rails_generators/shoulda_scaffold/templates/haml/layout.html.haml
|
57
|
-
- rails_generators/shoulda_scaffold/templates/haml/new.html.haml
|
58
|
-
- rails_generators/shoulda_scaffold/templates/haml/show.html.haml
|
59
|
-
- rails_generators/shoulda_scaffold/templates/helper.rb
|
60
|
-
- rails_generators/shoulda_scaffold/USAGE
|
25
|
+
- LICENSE
|
26
|
+
- Manifest
|
61
27
|
- Rakefile
|
62
28
|
- README.markdown
|
63
|
-
-
|
64
|
-
-
|
65
|
-
|
29
|
+
- TODO
|
30
|
+
- VERSION.yml
|
31
|
+
- test/fixtures
|
32
|
+
- test/fixtures/about_yml_plugins
|
33
|
+
- test/fixtures/about_yml_plugins/bad_about_yml
|
34
|
+
- test/fixtures/about_yml_plugins/bad_about_yml/about.yml
|
35
|
+
- test/fixtures/about_yml_plugins/bad_about_yml/init.rb
|
36
|
+
- test/fixtures/about_yml_plugins/plugin_without_about_yml
|
37
|
+
- test/fixtures/about_yml_plugins/plugin_without_about_yml/init.rb
|
38
|
+
- test/fixtures/eager
|
39
|
+
- test/fixtures/eager/zoo
|
40
|
+
- test/fixtures/eager/zoo/reptile_house.rb
|
41
|
+
- test/fixtures/eager/zoo.rb
|
42
|
+
- test/fixtures/environment_with_constant.rb
|
43
|
+
- test/fixtures/lib
|
44
|
+
- test/fixtures/lib/generators
|
45
|
+
- test/fixtures/lib/generators/missing_class
|
46
|
+
- test/fixtures/lib/generators/missing_class/missing_class_generator.rb
|
47
|
+
- test/fixtures/lib/generators/missing_class/templates
|
48
|
+
- test/fixtures/lib/generators/missing_generator
|
49
|
+
- test/fixtures/lib/generators/missing_generator/templates
|
50
|
+
- test/fixtures/lib/generators/missing_templates
|
51
|
+
- test/fixtures/lib/generators/working
|
52
|
+
- test/fixtures/lib/generators/working/working_generator.rb
|
53
|
+
- test/fixtures/plugins
|
54
|
+
- test/fixtures/plugins/alternate
|
55
|
+
- test/fixtures/plugins/alternate/a
|
56
|
+
- test/fixtures/plugins/alternate/a/generators
|
57
|
+
- test/fixtures/plugins/alternate/a/generators/a_generator
|
58
|
+
- test/fixtures/plugins/alternate/a/generators/a_generator/a_generator.rb
|
59
|
+
- test/fixtures/plugins/alternate/a/lib
|
60
|
+
- test/fixtures/plugins/default
|
61
|
+
- test/fixtures/plugins/default/acts
|
62
|
+
- test/fixtures/plugins/default/acts/acts_as_chunky_bacon
|
63
|
+
- test/fixtures/plugins/default/acts/acts_as_chunky_bacon/lib
|
64
|
+
- test/fixtures/plugins/default/empty
|
65
|
+
- test/fixtures/plugins/default/gemlike
|
66
|
+
- test/fixtures/plugins/default/gemlike/init.rb
|
67
|
+
- test/fixtures/plugins/default/gemlike/lib
|
68
|
+
- test/fixtures/plugins/default/gemlike/lib/gemlike.rb
|
69
|
+
- test/fixtures/plugins/default/gemlike/rails
|
70
|
+
- test/fixtures/plugins/default/gemlike/rails/init.rb
|
71
|
+
- test/fixtures/plugins/default/plugin_with_no_lib_dir
|
72
|
+
- test/fixtures/plugins/default/plugin_with_no_lib_dir/init.rb
|
73
|
+
- test/fixtures/plugins/default/stubby
|
74
|
+
- test/fixtures/plugins/default/stubby/about.yml
|
75
|
+
- test/fixtures/plugins/default/stubby/generators
|
76
|
+
- test/fixtures/plugins/default/stubby/generators/stubby_generator
|
77
|
+
- test/fixtures/plugins/default/stubby/generators/stubby_generator/stubby_generator.rb
|
78
|
+
- test/fixtures/plugins/default/stubby/init.rb
|
79
|
+
- test/fixtures/plugins/default/stubby/lib
|
80
|
+
- test/fixtures/plugins/default/stubby/lib/stubby_mixin.rb
|
81
|
+
- test/fixtures/tmp
|
82
|
+
- test/fixtures/tmp/test.log
|
83
|
+
- test/rails_generators
|
84
|
+
- test/rails_generators/shoulda_model_generator_test.rb
|
85
|
+
- test/shoulda_macros
|
86
|
+
- test/shoulda_macros/generator_macros.rb
|
87
|
+
- test/stolen_from_railties.rb
|
88
|
+
- test/test_helper.rb
|
89
|
+
has_rdoc: false
|
66
90
|
homepage: http://github.com/technicalpickles/shoulda_generator
|
67
91
|
post_install_message:
|
68
|
-
rdoc_options:
|
69
|
-
|
70
|
-
- --inline-source
|
71
|
-
- --title
|
72
|
-
- Shoulda_generator
|
73
|
-
- --main
|
74
|
-
- README.markdown
|
92
|
+
rdoc_options: []
|
93
|
+
|
75
94
|
require_paths:
|
76
95
|
- lib
|
77
96
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -82,13 +101,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
82
101
|
version:
|
83
102
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
103
|
requirements:
|
85
|
-
- - "
|
104
|
+
- - ">="
|
86
105
|
- !ruby/object:Gem::Version
|
87
|
-
version: "
|
106
|
+
version: "0"
|
88
107
|
version:
|
89
108
|
requirements: []
|
90
109
|
|
91
|
-
rubyforge_project:
|
110
|
+
rubyforge_project:
|
92
111
|
rubygems_version: 1.2.0
|
93
112
|
signing_key:
|
94
113
|
specification_version: 2
|
@@ -1,27 +0,0 @@
|
|
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, fixture, and migration:
|
20
|
-
Model: app/models/account.rb
|
21
|
-
Test: test/unit/account_test.rb
|
22
|
-
Factory: test/factories/accounts.rb
|
23
|
-
Migration: db/migrate/XXX_add_accounts.rb
|
24
|
-
|
25
|
-
`./script/generate model post title:string body:text published:boolean`
|
26
|
-
|
27
|
-
creates a Post model with a string title, text body, and published flag.
|
@@ -1,49 +0,0 @@
|
|
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-fixture",
|
47
|
-
"Don't generation a fixture file for this model") { |v| options[:skip_fixture] = v}
|
48
|
-
end
|
49
|
-
end
|
@@ -1,19 +0,0 @@
|
|
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 -%>
|
@@ -1,16 +0,0 @@
|
|
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
|
@@ -1,25 +0,0 @@
|
|
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
|
-
Examples:
|
23
|
-
`./script/generate scaffold post` # no attributes, view will be anemic
|
24
|
-
`./script/generate scaffold post title:string body:text published:boolean`
|
25
|
-
`./script/generate scaffold purchase order_id:integer amount:decimal`
|
@@ -1,107 +0,0 @@
|
|
1
|
-
class ShouldaScaffoldGenerator < Rails::Generator::NamedBase
|
2
|
-
default_options :skip_timestamps => false, :skip_migration => false, :skip_layout => true, :templating => 'haml', :functional_test_style => 'should_be_restful'
|
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
|
-
@controller_name = @name.pluralize
|
20
|
-
|
21
|
-
base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
|
22
|
-
@controller_class_name_without_nesting, @controller_underscore_name, @controller_plural_name = inflect_names(base_name)
|
23
|
-
@controller_singular_name=base_name.singularize
|
24
|
-
if @controller_class_nesting.empty?
|
25
|
-
@controller_class_name = @controller_class_name_without_nesting
|
26
|
-
else
|
27
|
-
@controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def manifest
|
32
|
-
record do |m|
|
33
|
-
# Check for class naming collisions.
|
34
|
-
m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
|
35
|
-
m.class_collisions(class_path, "#{class_name}")
|
36
|
-
|
37
|
-
# Controller, helper, views, and test directories.
|
38
|
-
m.directory(File.join('app/models', class_path))
|
39
|
-
m.directory(File.join('app/controllers', controller_class_path))
|
40
|
-
m.directory(File.join('app/helpers', controller_class_path))
|
41
|
-
m.directory(File.join('app/views', controller_class_path, controller_file_name))
|
42
|
-
m.directory(File.join('app/views/layouts', controller_class_path))
|
43
|
-
m.directory(File.join('test/functional', controller_class_path))
|
44
|
-
m.directory(File.join('test/unit', class_path))
|
45
|
-
|
46
|
-
m.directory('public/stylesheets/blueprint')
|
47
|
-
|
48
|
-
for view in scaffold_views
|
49
|
-
m.template(
|
50
|
-
"#{templating}/#{view}.html.#{templating}",
|
51
|
-
File.join('app/views', controller_class_path, controller_file_name, "#{view}.html.#{templating}")
|
52
|
-
)
|
53
|
-
end
|
54
|
-
|
55
|
-
# Layout and stylesheet.
|
56
|
-
m.template("#{templating}/layout.html.#{templating}", File.join('app/views/layouts', controller_class_path, "#{controller_file_name}.html.#{templating}"))
|
57
|
-
|
58
|
-
%w(print screen ie).each do |stylesheet|
|
59
|
-
m.template("blueprint/#{stylesheet}.css", "public/stylesheets/blueprint/#{stylesheet}.css")
|
60
|
-
end
|
61
|
-
|
62
|
-
m.template(
|
63
|
-
'controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
|
64
|
-
)
|
65
|
-
|
66
|
-
m.template("functional_test/#{functional_test_style}.rb", File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb"))
|
67
|
-
m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb"))
|
68
|
-
|
69
|
-
m.route_resources controller_file_name
|
70
|
-
|
71
|
-
m.dependency 'shoulda_model', [name] + @args, :collision => :skip
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def templating
|
76
|
-
options[:templating]
|
77
|
-
end
|
78
|
-
|
79
|
-
def functional_test_style
|
80
|
-
options[:functional_test_style]
|
81
|
-
end
|
82
|
-
|
83
|
-
protected
|
84
|
-
# Override with your own usage banner.
|
85
|
-
def banner
|
86
|
-
"Usage: #{$0} scaffold ModelName [field:type, field:type]"
|
87
|
-
end
|
88
|
-
|
89
|
-
def add_options!(opt)
|
90
|
-
opt.separator ''
|
91
|
-
opt.separator 'Options:'
|
92
|
-
opt.on("--skip-timestamps",
|
93
|
-
"Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v }
|
94
|
-
opt.on("--skip-migration",
|
95
|
-
"Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
|
96
|
-
opt.on("--templating [erb|haml]", "Specify the templating to use (haml by default)") { |v| options[:templating] = v }
|
97
|
-
opt.on("--functional-test-style [basic|should_be_restful]", "Specify the style of the functional test (should_be_restful by default)") { |v| options[:functional_test_style] = v }
|
98
|
-
end
|
99
|
-
|
100
|
-
def scaffold_views
|
101
|
-
%w[ index show new edit _form ]
|
102
|
-
end
|
103
|
-
|
104
|
-
def model_name
|
105
|
-
class_name.demodulize
|
106
|
-
end
|
107
|
-
end
|