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.

Files changed (148) hide show
  1. data/CHANGELOG +491 -12
  2. data/MIT-LICENSE +1 -1
  3. data/README +17 -25
  4. data/Rakefile +41 -18
  5. data/bin/about +1 -1
  6. data/bin/console +1 -1
  7. data/bin/destroy +1 -1
  8. data/bin/generate +1 -1
  9. data/bin/performance/request +3 -0
  10. data/bin/plugin +1 -1
  11. data/bin/runner +1 -1
  12. data/bin/server +1 -1
  13. data/builtin/rails_info/rails/info.rb +2 -2
  14. data/configs/apache.conf +1 -1
  15. data/configs/databases/mysql.yml +9 -3
  16. data/configs/databases/postgresql.yml +16 -12
  17. data/configs/initializers/inflections.rb +10 -0
  18. data/configs/initializers/mime_types.rb +5 -0
  19. data/configs/routes.rb +23 -11
  20. data/doc/README_FOR_APP +1 -1
  21. data/environments/boot.rb +95 -26
  22. data/environments/development.rb +2 -5
  23. data/environments/environment.rb +24 -25
  24. data/environments/test.rb +4 -1
  25. data/helpers/application.rb +5 -2
  26. data/helpers/test_helper.rb +10 -0
  27. data/html/422.html +30 -0
  28. data/html/500.html +1 -1
  29. data/html/index.html +2 -2
  30. data/html/javascripts/controls.js +484 -354
  31. data/html/javascripts/dragdrop.js +88 -58
  32. data/html/javascripts/effects.js +396 -364
  33. data/html/javascripts/prototype.js +2817 -1107
  34. data/html/robots.txt +5 -1
  35. data/lib/commands/console.rb +12 -5
  36. data/lib/commands/performance/request.rb +6 -0
  37. data/lib/commands/plugin.rb +15 -10
  38. data/lib/commands/process/spawner.rb +14 -4
  39. data/lib/commands/servers/base.rb +12 -0
  40. data/lib/commands/servers/mongrel.rb +5 -1
  41. data/lib/commands/servers/webrick.rb +14 -7
  42. data/lib/console_app.rb +5 -2
  43. data/lib/console_with_helpers.rb +5 -2
  44. data/lib/dispatcher.rb +3 -151
  45. data/lib/fcgi_handler.rb +79 -81
  46. data/lib/initializer.rb +125 -169
  47. data/lib/rails/plugin.rb +84 -0
  48. data/lib/rails/plugin/loader.rb +150 -0
  49. data/lib/rails/plugin/locator.rb +78 -0
  50. data/lib/rails/version.rb +3 -3
  51. data/lib/rails_generator/base.rb +11 -9
  52. data/lib/rails_generator/commands.rb +20 -10
  53. data/lib/rails_generator/generators/applications/app/USAGE +0 -7
  54. data/lib/rails_generator/generators/applications/app/app_generator.rb +25 -6
  55. data/lib/rails_generator/generators/components/controller/USAGE +11 -12
  56. data/lib/rails_generator/generators/components/controller/controller_generator.rb +2 -2
  57. data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +1 -11
  58. data/lib/rails_generator/generators/components/controller/templates/{view.rhtml → view.html.erb} +0 -0
  59. data/lib/rails_generator/generators/components/integration_test/USAGE +5 -11
  60. data/lib/rails_generator/generators/components/mailer/USAGE +8 -10
  61. data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +3 -3
  62. data/lib/rails_generator/generators/components/mailer/templates/fixture.erb +3 -0
  63. data/lib/rails_generator/generators/components/mailer/templates/fixture.rhtml +0 -3
  64. data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +8 -24
  65. data/lib/rails_generator/generators/components/mailer/templates/view.erb +3 -0
  66. data/lib/rails_generator/generators/components/mailer/templates/view.rhtml +0 -3
  67. data/lib/rails_generator/generators/components/migration/USAGE +23 -8
  68. data/lib/rails_generator/generators/components/migration/migration_generator.rb +15 -2
  69. data/lib/rails_generator/generators/components/migration/templates/migration.rb +6 -2
  70. data/lib/rails_generator/generators/components/model/USAGE +15 -14
  71. data/lib/rails_generator/generators/components/model/model_generator.rb +10 -3
  72. data/lib/rails_generator/generators/components/model/templates/fixtures.yml +11 -3
  73. data/lib/rails_generator/generators/components/model/templates/migration.rb +4 -1
  74. data/lib/rails_generator/generators/components/model/templates/unit_test.rb +1 -3
  75. data/lib/rails_generator/generators/components/observer/USAGE +5 -7
  76. data/lib/rails_generator/generators/components/observer/templates/unit_test.rb +0 -2
  77. data/lib/rails_generator/generators/components/plugin/USAGE +8 -18
  78. data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +1 -0
  79. data/lib/rails_generator/generators/components/plugin/templates/MIT-LICENSE +20 -0
  80. data/lib/rails_generator/generators/components/plugin/templates/README +10 -1
  81. data/lib/rails_generator/generators/components/plugin/templates/USAGE +1 -1
  82. data/lib/rails_generator/generators/components/plugin/templates/init.rb +1 -1
  83. data/lib/rails_generator/generators/components/plugin/templates/plugin.rb +1 -1
  84. data/lib/rails_generator/generators/components/plugin/templates/tasks.rake +1 -1
  85. data/lib/rails_generator/generators/components/resource/USAGE +23 -0
  86. data/lib/rails_generator/generators/components/resource/resource_generator.rb +13 -15
  87. data/lib/rails_generator/generators/components/resource/templates/controller.rb +1 -1
  88. data/lib/rails_generator/generators/components/resource/templates/functional_test.rb +2 -14
  89. data/lib/rails_generator/generators/components/scaffold/USAGE +24 -31
  90. data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +45 -146
  91. data/lib/rails_generator/generators/components/scaffold/templates/controller.rb +64 -37
  92. data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +23 -80
  93. data/lib/rails_generator/generators/components/scaffold/templates/{layout.rhtml → layout.html.erb} +0 -0
  94. data/lib/rails_generator/generators/components/scaffold/templates/style.css +1 -1
  95. data/lib/rails_generator/generators/components/{scaffold_resource/templates/view_edit.rhtml → scaffold/templates/view_edit.html.erb} +4 -4
  96. data/lib/rails_generator/generators/components/{scaffold_resource/templates/view_index.rhtml → scaffold/templates/view_index.html.erb} +4 -4
  97. data/lib/rails_generator/generators/components/{scaffold_resource/templates/view_new.rhtml → scaffold/templates/view_new.html.erb} +3 -3
  98. data/lib/rails_generator/generators/components/{scaffold_resource/templates/view_show.rhtml → scaffold/templates/view_show.html.erb} +1 -1
  99. data/lib/rails_generator/generators/components/session_migration/USAGE +6 -11
  100. data/lib/rails_generator/generators/components/session_migration/templates/migration.rb +3 -3
  101. data/lib/rails_generator/lookup.rb +45 -10
  102. data/lib/rails_generator/scripts.rb +6 -3
  103. data/lib/rails_generator/scripts/destroy.rb +23 -0
  104. data/lib/rails_generator/secret_key_generator.rb +160 -0
  105. data/lib/rails_generator/spec.rb +1 -1
  106. data/lib/source_annotation_extractor.rb +62 -0
  107. data/lib/tasks/annotations.rake +23 -0
  108. data/lib/tasks/databases.rake +249 -83
  109. data/lib/tasks/documentation.rake +11 -13
  110. data/lib/tasks/framework.rake +1 -1
  111. data/lib/tasks/rails.rb +1 -1
  112. data/lib/tasks/testing.rake +5 -7
  113. data/lib/test_help.rb +4 -3
  114. data/lib/webrick_server.rb +3 -4
  115. metadata +31 -49
  116. data/bin/breakpointer +0 -3
  117. data/lib/binding_of_caller.rb +0 -85
  118. data/lib/breakpoint.rb +0 -553
  119. data/lib/breakpoint_client.rb +0 -196
  120. data/lib/commands/breakpointer.rb +0 -1
  121. data/lib/rails_generator/generators/components/resource/templates/USAGE +0 -18
  122. data/lib/rails_generator/generators/components/resource/templates/fixtures.yml +0 -11
  123. data/lib/rails_generator/generators/components/resource/templates/migration.rb +0 -13
  124. data/lib/rails_generator/generators/components/resource/templates/model.rb +0 -2
  125. data/lib/rails_generator/generators/components/resource/templates/unit_test.rb +0 -10
  126. data/lib/rails_generator/generators/components/scaffold/templates/form.rhtml +0 -3
  127. data/lib/rails_generator/generators/components/scaffold/templates/form_scaffolding.rhtml +0 -1
  128. data/lib/rails_generator/generators/components/scaffold/templates/view_edit.rhtml +0 -9
  129. data/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml +0 -27
  130. data/lib/rails_generator/generators/components/scaffold/templates/view_new.rhtml +0 -8
  131. data/lib/rails_generator/generators/components/scaffold/templates/view_show.rhtml +0 -8
  132. data/lib/rails_generator/generators/components/scaffold_resource/USAGE +0 -29
  133. data/lib/rails_generator/generators/components/scaffold_resource/scaffold_resource_generator.rb +0 -93
  134. data/lib/rails_generator/generators/components/scaffold_resource/templates/controller.rb +0 -79
  135. data/lib/rails_generator/generators/components/scaffold_resource/templates/fixtures.yml +0 -11
  136. data/lib/rails_generator/generators/components/scaffold_resource/templates/functional_test.rb +0 -57
  137. data/lib/rails_generator/generators/components/scaffold_resource/templates/helper.rb +0 -2
  138. data/lib/rails_generator/generators/components/scaffold_resource/templates/layout.rhtml +0 -17
  139. data/lib/rails_generator/generators/components/scaffold_resource/templates/migration.rb +0 -13
  140. data/lib/rails_generator/generators/components/scaffold_resource/templates/model.rb +0 -2
  141. data/lib/rails_generator/generators/components/scaffold_resource/templates/style.css +0 -74
  142. data/lib/rails_generator/generators/components/scaffold_resource/templates/unit_test.rb +0 -10
  143. data/lib/rails_generator/generators/components/web_service/USAGE +0 -28
  144. data/lib/rails_generator/generators/components/web_service/templates/api_definition.rb +0 -5
  145. data/lib/rails_generator/generators/components/web_service/templates/controller.rb +0 -8
  146. data/lib/rails_generator/generators/components/web_service/templates/functional_test.rb +0 -19
  147. data/lib/rails_generator/generators/components/web_service/web_service_generator.rb +0 -29
  148. 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,4 +1,13 @@
1
1
  <%= class_name %>
2
2
  <%= "=" * class_name.size %>
3
3
 
4
- Description goes here
4
+ Introduction goes here.
5
+
6
+
7
+ Example
8
+ =======
9
+
10
+ Example goes here.
11
+
12
+
13
+ Copyright (c) <%= Date.today.year %> [name of plugin creator], released under the MIT license
@@ -5,4 +5,4 @@ Example:
5
5
  ./script/generate <%= file_name %> Thing
6
6
 
7
7
  This will create:
8
- what/will/it/create
8
+ what/will/it/create
@@ -1 +1 @@
1
- # Include hook code here
1
+ # Include hook code here
@@ -1 +1 @@
1
- # <%= class_name %>
1
+ # <%= class_name %>
@@ -1,4 +1,4 @@
1
1
  # desc "Explaining what the task does"
2
2
  # task :<%= file_name %> do
3
3
  # # Task goes here
4
- # end
4
+ # end
@@ -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.template('model.rb', File.join('app/models', class_path, "#{file_name}.rb"))
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 model_name
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__) + '<%= '/..' * controller_class_nesting_depth %>/../test_helper'
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
- The scaffold generator creates a controller to interact with a model.
3
- If the model does not exist, it creates the model as well. The generated
4
- code is equivalent to the "scaffold :model" declaration, making it easy
5
- to migrate when you wish to customize your controller and views.
6
-
7
- The generator takes a model name, an optional controller name, and a
8
- list of views as arguments. Scaffolded actions and views are created
9
- automatically. Any views left over generate empty stubs.
10
-
11
- The scaffolded actions and views are:
12
- index, list, show, new, create, edit, update, destroy
13
-
14
- If a controller name is not given, the plural form of the model name
15
- will be used. The model and controller names may be given in CamelCase
16
- or under_score and should not be suffixed with 'Model' or 'Controller'.
17
- Both model and controller names may be prefixed with a module like a
18
- file path; see the Modules Example for usage.
19
-
20
- Example:
21
- ./script/generate scaffold Account Bank debit credit
22
-
23
- This will generate an Account model and BankController with a full test
24
- suite and a basic user interface. Now create the accounts table in your
25
- database and browse to http://localhost/bank/ -- voila, you're on Rails!
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, :controller_singular_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
- # Take controller name from the next argument. Default to the pluralized model name.
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, @controller_singular_name, @controller_plural_name = inflect_names(base_name)
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 controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}ControllerTest", "#{controller_class_name}Helper"
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 File.join('app/controllers', controller_class_path)
75
- m.directory File.join('app/helpers', controller_class_path)
76
- m.directory File.join('app/views', controller_class_path, controller_file_name)
77
- m.directory File.join('app/views/layouts', controller_class_path)
78
- m.directory File.join('test/functional', controller_class_path)
79
-
80
- # Depend on model generator but skip if the model exists.
81
- m.dependency 'model', [singular_name], :collision => :skip, :skip_migration => true
82
-
83
- # Scaffolded forms.
84
- m.complex_template "form.rhtml",
85
- File.join('app/views',
86
- controller_class_path,
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
- # Controller class, functional test, helper, and views.
107
- m.template 'controller.rb',
108
- File.join('app/controllers',
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.template 'functional_test.rb',
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 'helper.rb',
118
- File.join('app/helpers',
119
- controller_class_path,
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
- # Layout and stylesheet.
123
- m.template 'layout.rhtml',
124
- File.join('app/views/layouts',
125
- controller_class_path,
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 [ControllerName] [action, ...]"
73
+ "Usage: #{$0} scaffold ModelName [field:type, field:type]"
147
74
  end
148
75
 
149
- def scaffold_views
150
- %w(list show new edit)
151
- end
152
-
153
- def scaffold_actions
154
- scaffold_views + %w(index create update destroy)
155
- end
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 unscaffolded_actions
162
- args - scaffold_actions
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 create_sandbox
170
- sandbox = ScaffoldingSandbox.new
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