rails 1.2.6 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rails might be problematic. Click here for more details.
- data/CHANGELOG +491 -12
- data/MIT-LICENSE +1 -1
- data/README +17 -25
- data/Rakefile +41 -18
- data/bin/about +1 -1
- data/bin/console +1 -1
- data/bin/destroy +1 -1
- data/bin/generate +1 -1
- data/bin/performance/request +3 -0
- data/bin/plugin +1 -1
- data/bin/runner +1 -1
- data/bin/server +1 -1
- data/builtin/rails_info/rails/info.rb +2 -2
- data/configs/apache.conf +1 -1
- data/configs/databases/mysql.yml +9 -3
- data/configs/databases/postgresql.yml +16 -12
- data/configs/initializers/inflections.rb +10 -0
- data/configs/initializers/mime_types.rb +5 -0
- data/configs/routes.rb +23 -11
- data/doc/README_FOR_APP +1 -1
- data/environments/boot.rb +95 -26
- data/environments/development.rb +2 -5
- data/environments/environment.rb +24 -25
- data/environments/test.rb +4 -1
- data/helpers/application.rb +5 -2
- data/helpers/test_helper.rb +10 -0
- data/html/422.html +30 -0
- data/html/500.html +1 -1
- data/html/index.html +2 -2
- data/html/javascripts/controls.js +484 -354
- data/html/javascripts/dragdrop.js +88 -58
- data/html/javascripts/effects.js +396 -364
- data/html/javascripts/prototype.js +2817 -1107
- data/html/robots.txt +5 -1
- data/lib/commands/console.rb +12 -5
- data/lib/commands/performance/request.rb +6 -0
- data/lib/commands/plugin.rb +15 -10
- data/lib/commands/process/spawner.rb +14 -4
- data/lib/commands/servers/base.rb +12 -0
- data/lib/commands/servers/mongrel.rb +5 -1
- data/lib/commands/servers/webrick.rb +14 -7
- data/lib/console_app.rb +5 -2
- data/lib/console_with_helpers.rb +5 -2
- data/lib/dispatcher.rb +3 -151
- data/lib/fcgi_handler.rb +79 -81
- data/lib/initializer.rb +125 -169
- data/lib/rails/plugin.rb +84 -0
- data/lib/rails/plugin/loader.rb +150 -0
- data/lib/rails/plugin/locator.rb +78 -0
- data/lib/rails/version.rb +3 -3
- data/lib/rails_generator/base.rb +11 -9
- data/lib/rails_generator/commands.rb +20 -10
- data/lib/rails_generator/generators/applications/app/USAGE +0 -7
- data/lib/rails_generator/generators/applications/app/app_generator.rb +25 -6
- data/lib/rails_generator/generators/components/controller/USAGE +11 -12
- data/lib/rails_generator/generators/components/controller/controller_generator.rb +2 -2
- data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +1 -11
- data/lib/rails_generator/generators/components/controller/templates/{view.rhtml → view.html.erb} +0 -0
- data/lib/rails_generator/generators/components/integration_test/USAGE +5 -11
- data/lib/rails_generator/generators/components/mailer/USAGE +8 -10
- data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +3 -3
- data/lib/rails_generator/generators/components/mailer/templates/fixture.erb +3 -0
- data/lib/rails_generator/generators/components/mailer/templates/fixture.rhtml +0 -3
- data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +8 -24
- data/lib/rails_generator/generators/components/mailer/templates/view.erb +3 -0
- data/lib/rails_generator/generators/components/mailer/templates/view.rhtml +0 -3
- data/lib/rails_generator/generators/components/migration/USAGE +23 -8
- data/lib/rails_generator/generators/components/migration/migration_generator.rb +15 -2
- data/lib/rails_generator/generators/components/migration/templates/migration.rb +6 -2
- data/lib/rails_generator/generators/components/model/USAGE +15 -14
- data/lib/rails_generator/generators/components/model/model_generator.rb +10 -3
- data/lib/rails_generator/generators/components/model/templates/fixtures.yml +11 -3
- data/lib/rails_generator/generators/components/model/templates/migration.rb +4 -1
- data/lib/rails_generator/generators/components/model/templates/unit_test.rb +1 -3
- data/lib/rails_generator/generators/components/observer/USAGE +5 -7
- data/lib/rails_generator/generators/components/observer/templates/unit_test.rb +0 -2
- data/lib/rails_generator/generators/components/plugin/USAGE +8 -18
- data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +1 -0
- data/lib/rails_generator/generators/components/plugin/templates/MIT-LICENSE +20 -0
- data/lib/rails_generator/generators/components/plugin/templates/README +10 -1
- data/lib/rails_generator/generators/components/plugin/templates/USAGE +1 -1
- data/lib/rails_generator/generators/components/plugin/templates/init.rb +1 -1
- data/lib/rails_generator/generators/components/plugin/templates/plugin.rb +1 -1
- data/lib/rails_generator/generators/components/plugin/templates/tasks.rake +1 -1
- data/lib/rails_generator/generators/components/resource/USAGE +23 -0
- data/lib/rails_generator/generators/components/resource/resource_generator.rb +13 -15
- data/lib/rails_generator/generators/components/resource/templates/controller.rb +1 -1
- data/lib/rails_generator/generators/components/resource/templates/functional_test.rb +2 -14
- data/lib/rails_generator/generators/components/scaffold/USAGE +24 -31
- data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +45 -146
- data/lib/rails_generator/generators/components/scaffold/templates/controller.rb +64 -37
- data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +23 -80
- data/lib/rails_generator/generators/components/scaffold/templates/{layout.rhtml → layout.html.erb} +0 -0
- data/lib/rails_generator/generators/components/scaffold/templates/style.css +1 -1
- data/lib/rails_generator/generators/components/{scaffold_resource/templates/view_edit.rhtml → scaffold/templates/view_edit.html.erb} +4 -4
- data/lib/rails_generator/generators/components/{scaffold_resource/templates/view_index.rhtml → scaffold/templates/view_index.html.erb} +4 -4
- data/lib/rails_generator/generators/components/{scaffold_resource/templates/view_new.rhtml → scaffold/templates/view_new.html.erb} +3 -3
- data/lib/rails_generator/generators/components/{scaffold_resource/templates/view_show.rhtml → scaffold/templates/view_show.html.erb} +1 -1
- data/lib/rails_generator/generators/components/session_migration/USAGE +6 -11
- data/lib/rails_generator/generators/components/session_migration/templates/migration.rb +3 -3
- data/lib/rails_generator/lookup.rb +45 -10
- data/lib/rails_generator/scripts.rb +6 -3
- data/lib/rails_generator/scripts/destroy.rb +23 -0
- data/lib/rails_generator/secret_key_generator.rb +160 -0
- data/lib/rails_generator/spec.rb +1 -1
- data/lib/source_annotation_extractor.rb +62 -0
- data/lib/tasks/annotations.rake +23 -0
- data/lib/tasks/databases.rake +249 -83
- data/lib/tasks/documentation.rake +11 -13
- data/lib/tasks/framework.rake +1 -1
- data/lib/tasks/rails.rb +1 -1
- data/lib/tasks/testing.rake +5 -7
- data/lib/test_help.rb +4 -3
- data/lib/webrick_server.rb +3 -4
- metadata +31 -49
- data/bin/breakpointer +0 -3
- data/lib/binding_of_caller.rb +0 -85
- data/lib/breakpoint.rb +0 -553
- data/lib/breakpoint_client.rb +0 -196
- data/lib/commands/breakpointer.rb +0 -1
- data/lib/rails_generator/generators/components/resource/templates/USAGE +0 -18
- data/lib/rails_generator/generators/components/resource/templates/fixtures.yml +0 -11
- data/lib/rails_generator/generators/components/resource/templates/migration.rb +0 -13
- data/lib/rails_generator/generators/components/resource/templates/model.rb +0 -2
- data/lib/rails_generator/generators/components/resource/templates/unit_test.rb +0 -10
- data/lib/rails_generator/generators/components/scaffold/templates/form.rhtml +0 -3
- data/lib/rails_generator/generators/components/scaffold/templates/form_scaffolding.rhtml +0 -1
- data/lib/rails_generator/generators/components/scaffold/templates/view_edit.rhtml +0 -9
- data/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml +0 -27
- data/lib/rails_generator/generators/components/scaffold/templates/view_new.rhtml +0 -8
- data/lib/rails_generator/generators/components/scaffold/templates/view_show.rhtml +0 -8
- data/lib/rails_generator/generators/components/scaffold_resource/USAGE +0 -29
- data/lib/rails_generator/generators/components/scaffold_resource/scaffold_resource_generator.rb +0 -93
- data/lib/rails_generator/generators/components/scaffold_resource/templates/controller.rb +0 -79
- data/lib/rails_generator/generators/components/scaffold_resource/templates/fixtures.yml +0 -11
- data/lib/rails_generator/generators/components/scaffold_resource/templates/functional_test.rb +0 -57
- data/lib/rails_generator/generators/components/scaffold_resource/templates/helper.rb +0 -2
- data/lib/rails_generator/generators/components/scaffold_resource/templates/layout.rhtml +0 -17
- data/lib/rails_generator/generators/components/scaffold_resource/templates/migration.rb +0 -13
- data/lib/rails_generator/generators/components/scaffold_resource/templates/model.rb +0 -2
- data/lib/rails_generator/generators/components/scaffold_resource/templates/style.css +0 -74
- data/lib/rails_generator/generators/components/scaffold_resource/templates/unit_test.rb +0 -10
- data/lib/rails_generator/generators/components/web_service/USAGE +0 -28
- data/lib/rails_generator/generators/components/web_service/templates/api_definition.rb +0 -5
- data/lib/rails_generator/generators/components/web_service/templates/controller.rb +0 -8
- data/lib/rails_generator/generators/components/web_service/templates/functional_test.rb +0 -19
- data/lib/rails_generator/generators/components/web_service/web_service_generator.rb +0 -29
- data/lib/tasks/pre_namespace_aliases.rake +0 -53
@@ -17,6 +17,7 @@ class PluginGenerator < Rails::Generator::NamedBase
|
|
17
17
|
m.directory "#{plugin_path}/test"
|
18
18
|
|
19
19
|
m.template 'README', "#{plugin_path}/README"
|
20
|
+
m.template 'MIT-LICENSE', "#{plugin_path}/MIT-LICENSE"
|
20
21
|
m.template 'Rakefile', "#{plugin_path}/Rakefile"
|
21
22
|
m.template 'init.rb', "#{plugin_path}/init.rb"
|
22
23
|
m.template 'install.rb', "#{plugin_path}/install.rb"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) <%= Date.today.year %> [name of plugin creator]
|
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.
|
@@ -1 +1 @@
|
|
1
|
-
# Include hook code here
|
1
|
+
# Include hook code here
|
@@ -1 +1 @@
|
|
1
|
-
# <%= class_name %>
|
1
|
+
# <%= class_name %>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Description:
|
2
|
+
Stubs out a new resource including an empty model and controller suitable
|
3
|
+
for a restful, resource-oriented application. Pass the singular model name,
|
4
|
+
either CamelCased or under_scored, as the first argument, and an optional
|
5
|
+
list of attribute pairs.
|
6
|
+
|
7
|
+
Attribute pairs are column_name:sql_type arguments specifying the
|
8
|
+
model's attributes. Timestamps are added by default, so you don't have to
|
9
|
+
specify them by hand as 'created_at:datetime updated_at:datetime'.
|
10
|
+
|
11
|
+
You don't have to think up every attribute up front, but it helps to
|
12
|
+
sketch out a few so you can start working with the resource immediately.
|
13
|
+
|
14
|
+
This creates a model, controller, tests and fixtures for both, and the
|
15
|
+
corresponding map.resources declaration in config/routes.rb
|
16
|
+
|
17
|
+
Unlike the scaffold generator, the resource generator does not create
|
18
|
+
views or add any methods to the generated controller.
|
19
|
+
|
20
|
+
Examples:
|
21
|
+
`./script/generate resource post` # no attributes
|
22
|
+
`./script/generate resource post title:string body:text published:boolean`
|
23
|
+
`./script/generate resource purchase order_id:integer amount:decimal`
|
@@ -1,4 +1,6 @@
|
|
1
1
|
class ResourceGenerator < Rails::Generator::NamedBase
|
2
|
+
default_options :skip_timestamps => false, :skip_migration => false
|
3
|
+
|
2
4
|
attr_reader :controller_name,
|
3
5
|
:controller_class_path,
|
4
6
|
:controller_file_path,
|
@@ -39,7 +41,7 @@ class ResourceGenerator < Rails::Generator::NamedBase
|
|
39
41
|
m.directory(File.join('test/functional', controller_class_path))
|
40
42
|
m.directory(File.join('test/unit', class_path))
|
41
43
|
|
42
|
-
m.
|
44
|
+
m.dependency 'model', [name] + @args, :collision => :skip
|
43
45
|
|
44
46
|
m.template(
|
45
47
|
'controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
|
@@ -47,19 +49,6 @@ class ResourceGenerator < Rails::Generator::NamedBase
|
|
47
49
|
|
48
50
|
m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb"))
|
49
51
|
m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb"))
|
50
|
-
m.template('unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb"))
|
51
|
-
m.template('fixtures.yml', File.join('test/fixtures', "#{table_name}.yml"))
|
52
|
-
|
53
|
-
unless options[:skip_migration]
|
54
|
-
m.migration_template(
|
55
|
-
'migration.rb', 'db/migrate',
|
56
|
-
:assigns => {
|
57
|
-
:migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}",
|
58
|
-
:attributes => attributes
|
59
|
-
},
|
60
|
-
:migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
|
61
|
-
)
|
62
|
-
end
|
63
52
|
|
64
53
|
m.route_resources controller_file_name
|
65
54
|
end
|
@@ -70,7 +59,16 @@ class ResourceGenerator < Rails::Generator::NamedBase
|
|
70
59
|
"Usage: #{$0} resource ModelName [field:type, field:type]"
|
71
60
|
end
|
72
61
|
|
73
|
-
def
|
62
|
+
def add_options!(opt)
|
63
|
+
opt.separator ''
|
64
|
+
opt.separator 'Options:'
|
65
|
+
opt.on("--skip-timestamps",
|
66
|
+
"Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v }
|
67
|
+
opt.on("--skip-migration",
|
68
|
+
"Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
|
69
|
+
end
|
70
|
+
|
71
|
+
def model_name
|
74
72
|
class_name.demodulize
|
75
73
|
end
|
76
74
|
end
|
@@ -1,2 +1,2 @@
|
|
1
1
|
class <%= controller_class_name %>Controller < ApplicationController
|
2
|
-
end
|
2
|
+
end
|
@@ -1,18 +1,6 @@
|
|
1
|
-
require File.dirname(__FILE__) + '<%= '/..' *
|
2
|
-
require '<%= controller_file_path %>_controller'
|
3
|
-
|
4
|
-
# Re-raise errors caught by the controller.
|
5
|
-
class <%= controller_class_name %>Controller; def rescue_action(e) raise e end; end
|
6
|
-
|
7
|
-
class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase
|
8
|
-
fixtures :<%= table_name %>
|
9
|
-
|
10
|
-
def setup
|
11
|
-
@controller = <%= controller_class_name %>Controller.new
|
12
|
-
@request = ActionController::TestRequest.new
|
13
|
-
@response = ActionController::TestResponse.new
|
14
|
-
end
|
1
|
+
require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper'
|
15
2
|
|
3
|
+
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
|
16
4
|
# Replace this with your real tests.
|
17
5
|
def test_truth
|
18
6
|
assert true
|
@@ -1,32 +1,25 @@
|
|
1
1
|
Description:
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
Modules Example:
|
28
|
-
./script/generate scaffold CreditCard 'admin/credit_card' suspend late_fee
|
29
|
-
|
30
|
-
This will generate a CreditCard model and CreditCardController controller
|
31
|
-
in the admin module.
|
32
|
-
|
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,63 +1,26 @@
|
|
1
|
-
class ScaffoldingSandbox
|
2
|
-
include ActionView::Helpers::ActiveRecordHelper
|
3
|
-
|
4
|
-
attr_accessor :form_action, :singular_name, :suffix, :model_instance
|
5
|
-
|
6
|
-
def sandbox_binding
|
7
|
-
binding
|
8
|
-
end
|
9
|
-
|
10
|
-
def default_input_block
|
11
|
-
Proc.new { |record, column| "<p><label for=\"#{record}_#{column.name}\">#{column.human_name}</label><br/>\n#{input(record, column.name)}</p>\n" }
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
class ActionView::Helpers::InstanceTag
|
17
|
-
def to_input_field_tag(field_type, options={})
|
18
|
-
field_meth = "#{field_type}_field"
|
19
|
-
"<%= #{field_meth} '#{@object_name}', '#{@method_name}' #{options.empty? ? '' : ', '+options.inspect} %>"
|
20
|
-
end
|
21
|
-
|
22
|
-
def to_text_area_tag(options = {})
|
23
|
-
"<%= text_area '#{@object_name}', '#{@method_name}' #{options.empty? ? '' : ', '+ options.inspect} %>"
|
24
|
-
end
|
25
|
-
|
26
|
-
def to_date_select_tag(options = {})
|
27
|
-
"<%= date_select '#{@object_name}', '#{@method_name}' #{options.empty? ? '' : ', '+ options.inspect} %>"
|
28
|
-
end
|
29
|
-
|
30
|
-
def to_datetime_select_tag(options = {})
|
31
|
-
"<%= datetime_select '#{@object_name}', '#{@method_name}' #{options.empty? ? '' : ', '+ options.inspect} %>"
|
32
|
-
end
|
33
|
-
|
34
|
-
def to_time_select_tag(options = {})
|
35
|
-
"<%= time_select '#{@object_name}', '#{@method_name}' #{options.empty? ? '' : ', '+ options.inspect} %>"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
1
|
class ScaffoldGenerator < Rails::Generator::NamedBase
|
2
|
+
default_options :skip_timestamps => false, :skip_migration => false
|
3
|
+
|
40
4
|
attr_reader :controller_name,
|
41
5
|
:controller_class_path,
|
42
6
|
:controller_file_path,
|
43
7
|
:controller_class_nesting,
|
44
8
|
:controller_class_nesting_depth,
|
45
9
|
:controller_class_name,
|
10
|
+
:controller_underscore_name,
|
46
11
|
:controller_singular_name,
|
47
12
|
:controller_plural_name
|
48
|
-
alias_method :controller_file_name, :
|
13
|
+
alias_method :controller_file_name, :controller_underscore_name
|
49
14
|
alias_method :controller_table_name, :controller_plural_name
|
50
15
|
|
51
16
|
def initialize(runtime_args, runtime_options = {})
|
52
17
|
super
|
53
18
|
|
54
|
-
|
55
|
-
@controller_name = args.shift
|
56
|
-
@controller_name ||= ActiveRecord::Base.pluralize_table_names ? @name.pluralize : @name
|
19
|
+
@controller_name = @name.pluralize
|
57
20
|
|
58
21
|
base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
|
59
|
-
@controller_class_name_without_nesting, @
|
60
|
-
|
22
|
+
@controller_class_name_without_nesting, @controller_underscore_name, @controller_plural_name = inflect_names(base_name)
|
23
|
+
@controller_singular_name=base_name.singularize
|
61
24
|
if @controller_class_nesting.empty?
|
62
25
|
@controller_class_name = @controller_class_name_without_nesting
|
63
26
|
else
|
@@ -68,126 +31,62 @@ class ScaffoldGenerator < Rails::Generator::NamedBase
|
|
68
31
|
def manifest
|
69
32
|
record do |m|
|
70
33
|
# Check for class naming collisions.
|
71
|
-
m.class_collisions
|
34
|
+
m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
|
35
|
+
m.class_collisions(class_path, "#{class_name}")
|
72
36
|
|
73
37
|
# Controller, helper, views, and test directories.
|
74
|
-
m.directory
|
75
|
-
m.directory
|
76
|
-
m.directory
|
77
|
-
m.directory
|
78
|
-
m.directory
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
controller_file_name,
|
88
|
-
"_form.rhtml"),
|
89
|
-
:insert => 'form_scaffolding.rhtml',
|
90
|
-
:sandbox => lambda { create_sandbox },
|
91
|
-
:begin_mark => 'form',
|
92
|
-
:end_mark => 'eoform',
|
93
|
-
:mark_id => singular_name
|
94
|
-
|
95
|
-
|
96
|
-
# Scaffolded views.
|
97
|
-
scaffold_views.each do |action|
|
98
|
-
m.template "view_#{action}.rhtml",
|
99
|
-
File.join('app/views',
|
100
|
-
controller_class_path,
|
101
|
-
controller_file_name,
|
102
|
-
"#{action}.rhtml"),
|
103
|
-
:assigns => { :action => action }
|
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
|
+
for action in scaffold_views
|
47
|
+
m.template(
|
48
|
+
"view_#{action}.html.erb",
|
49
|
+
File.join('app/views', controller_class_path, controller_file_name, "#{action}.html.erb")
|
50
|
+
)
|
104
51
|
end
|
105
52
|
|
106
|
-
#
|
107
|
-
m.template
|
108
|
-
|
109
|
-
controller_class_path,
|
110
|
-
"#{controller_file_name}_controller.rb")
|
53
|
+
# Layout and stylesheet.
|
54
|
+
m.template('layout.html.erb', File.join('app/views/layouts', controller_class_path, "#{controller_file_name}.html.erb"))
|
55
|
+
m.template('style.css', 'public/stylesheets/scaffold.css')
|
111
56
|
|
112
|
-
m.
|
113
|
-
File.join('test/functional',
|
114
|
-
controller_class_path,
|
115
|
-
"#{controller_file_name}_controller_test.rb")
|
57
|
+
m.dependency 'model', [name] + @args, :collision => :skip
|
116
58
|
|
117
|
-
m.template
|
118
|
-
|
119
|
-
|
120
|
-
"#{controller_file_name}_helper.rb")
|
59
|
+
m.template(
|
60
|
+
'controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
|
61
|
+
)
|
121
62
|
|
122
|
-
|
123
|
-
m.template
|
124
|
-
|
125
|
-
|
126
|
-
"#{controller_file_name}.rhtml")
|
127
|
-
|
128
|
-
m.template 'style.css', 'public/stylesheets/scaffold.css'
|
129
|
-
|
130
|
-
|
131
|
-
# Unscaffolded views.
|
132
|
-
unscaffolded_actions.each do |action|
|
133
|
-
path = File.join('app/views',
|
134
|
-
controller_class_path,
|
135
|
-
controller_file_name,
|
136
|
-
"#{action}.rhtml")
|
137
|
-
m.template "controller:view.rhtml", path,
|
138
|
-
:assigns => { :action => action, :path => path}
|
139
|
-
end
|
63
|
+
m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb"))
|
64
|
+
m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb"))
|
65
|
+
|
66
|
+
m.route_resources controller_file_name
|
140
67
|
end
|
141
68
|
end
|
142
69
|
|
143
70
|
protected
|
144
71
|
# Override with your own usage banner.
|
145
72
|
def banner
|
146
|
-
"Usage: #{$0} scaffold ModelName [
|
73
|
+
"Usage: #{$0} scaffold ModelName [field:type, field:type]"
|
147
74
|
end
|
148
75
|
|
149
|
-
def
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
def model_name
|
158
|
-
class_name.demodulize
|
76
|
+
def add_options!(opt)
|
77
|
+
opt.separator ''
|
78
|
+
opt.separator 'Options:'
|
79
|
+
opt.on("--skip-timestamps",
|
80
|
+
"Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v }
|
81
|
+
opt.on("--skip-migration",
|
82
|
+
"Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
|
159
83
|
end
|
160
84
|
|
161
|
-
def
|
162
|
-
|
163
|
-
end
|
164
|
-
|
165
|
-
def suffix
|
166
|
-
"_#{singular_name}" if options[:suffix]
|
85
|
+
def scaffold_views
|
86
|
+
%w[ index show new edit ]
|
167
87
|
end
|
168
88
|
|
169
|
-
def
|
170
|
-
|
171
|
-
sandbox.singular_name = singular_name
|
172
|
-
begin
|
173
|
-
sandbox.model_instance = model_instance
|
174
|
-
sandbox.instance_variable_set("@#{singular_name}", sandbox.model_instance)
|
175
|
-
rescue ActiveRecord::StatementInvalid => e
|
176
|
-
logger.error "Before updating scaffolding from new DB schema, try creating a table for your model (#{class_name}) named #{class_name.tableize}."
|
177
|
-
raise SystemExit
|
178
|
-
end
|
179
|
-
sandbox.suffix = suffix
|
180
|
-
sandbox
|
181
|
-
end
|
182
|
-
|
183
|
-
def model_instance
|
184
|
-
base = class_nesting.split('::').inject(Object) do |base, nested|
|
185
|
-
break base.const_get(nested) if base.const_defined?(nested)
|
186
|
-
base.const_set(nested, Module.new)
|
187
|
-
end
|
188
|
-
unless base.const_defined?(@class_name_without_nesting)
|
189
|
-
base.const_set(@class_name_without_nesting, Class.new(ActiveRecord::Base))
|
190
|
-
end
|
191
|
-
class_name.constantize.new
|
89
|
+
def model_name
|
90
|
+
class_name.demodulize
|
192
91
|
end
|
193
92
|
end
|