rails 0.9.5 → 0.10.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 (77) hide show
  1. data/CHANGELOG +46 -0
  2. data/README +36 -8
  3. data/Rakefile +18 -25
  4. data/bin/console +17 -30
  5. data/bin/console_sandbox.rb +6 -0
  6. data/bin/destroy +5 -0
  7. data/bin/generate +2 -70
  8. data/bin/rails +4 -28
  9. data/bin/server +4 -2
  10. data/bin/update +5 -0
  11. data/configs/apache.conf +7 -54
  12. data/configs/empty.log +0 -0
  13. data/configs/routes.rb +15 -0
  14. data/environments/shared.rb +14 -6
  15. data/environments/shared_for_gem.rb +12 -6
  16. data/fresh_rakefile +40 -8
  17. data/html/index.html +70 -1
  18. data/lib/breakpoint.rb +6 -1
  19. data/lib/breakpoint_client.rb +196 -193
  20. data/lib/dispatcher.rb +16 -38
  21. data/lib/rails_generator.rb +39 -198
  22. data/lib/rails_generator/base.rb +203 -0
  23. data/lib/rails_generator/commands.rb +409 -0
  24. data/lib/rails_generator/generators/applications/app/USAGE +16 -0
  25. data/lib/rails_generator/generators/applications/app/app_generator.rb +120 -0
  26. data/lib/rails_generator/generators/components/controller/USAGE +30 -0
  27. data/lib/rails_generator/generators/components/controller/controller_generator.rb +37 -0
  28. data/{generators → lib/rails_generator/generators/components}/controller/templates/controller.rb +1 -1
  29. data/lib/rails_generator/generators/components/controller/templates/functional_test.rb +18 -0
  30. data/{generators → lib/rails_generator/generators/components}/controller/templates/helper.rb +0 -0
  31. data/{generators → lib/rails_generator/generators/components}/controller/templates/view.rhtml +0 -0
  32. data/lib/rails_generator/generators/components/mailer/USAGE +19 -0
  33. data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +32 -0
  34. data/{generators → lib/rails_generator/generators/components}/mailer/templates/fixture.rhtml +0 -0
  35. data/{generators → lib/rails_generator/generators/components}/mailer/templates/mailer.rb +0 -0
  36. data/{generators → lib/rails_generator/generators/components}/mailer/templates/unit_test.rb +7 -1
  37. data/{generators → lib/rails_generator/generators/components}/mailer/templates/view.rhtml +0 -0
  38. data/lib/rails_generator/generators/components/model/USAGE +17 -0
  39. data/lib/rails_generator/generators/components/model/model_generator.rb +18 -0
  40. data/{generators/scaffold → lib/rails_generator/generators/components/model}/templates/fixtures.yml +0 -2
  41. data/{generators → lib/rails_generator/generators/components}/model/templates/model.rb +0 -0
  42. data/{generators → lib/rails_generator/generators/components}/model/templates/unit_test.rb +5 -1
  43. data/lib/rails_generator/generators/components/scaffold/USAGE +32 -0
  44. data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +178 -0
  45. data/{generators → lib/rails_generator/generators/components}/scaffold/templates/controller.rb +1 -1
  46. data/lib/rails_generator/generators/components/scaffold/templates/form.rhtml +5 -0
  47. data/{generators → lib/rails_generator/generators/components}/scaffold/templates/functional_test.rb +7 -6
  48. data/lib/rails_generator/generators/components/scaffold/templates/helper.rb +2 -0
  49. data/{generators → lib/rails_generator/generators/components}/scaffold/templates/layout.rhtml +1 -1
  50. data/{generators → lib/rails_generator/generators/components}/scaffold/templates/style.css +17 -17
  51. data/{generators → lib/rails_generator/generators/components}/scaffold/templates/view_edit.rhtml +1 -1
  52. data/{generators → lib/rails_generator/generators/components}/scaffold/templates/view_list.rhtml +1 -1
  53. data/{generators → lib/rails_generator/generators/components}/scaffold/templates/view_new.rhtml +1 -1
  54. data/{generators → lib/rails_generator/generators/components}/scaffold/templates/view_show.rhtml +0 -0
  55. data/lib/rails_generator/lookup.rb +200 -0
  56. data/lib/rails_generator/manifest.rb +53 -0
  57. data/lib/rails_generator/options.rb +134 -0
  58. data/lib/rails_generator/scripts.rb +83 -0
  59. data/lib/rails_generator/scripts/destroy.rb +7 -0
  60. data/lib/rails_generator/scripts/generate.rb +7 -0
  61. data/lib/rails_generator/scripts/update.rb +12 -0
  62. data/lib/rails_generator/simple_logger.rb +46 -0
  63. data/lib/rails_generator/spec.rb +44 -0
  64. data/lib/webrick_server.rb +15 -65
  65. metadata +92 -48
  66. data/doc/apache_protection +0 -3
  67. data/doc/index.html +0 -70
  68. data/generators/controller/USAGE +0 -28
  69. data/generators/controller/controller_generator.rb +0 -26
  70. data/generators/controller/templates/functional_test.rb +0 -17
  71. data/generators/mailer/USAGE +0 -27
  72. data/generators/mailer/mailer_generator.rb +0 -22
  73. data/generators/model/USAGE +0 -17
  74. data/generators/model/model_generator.rb +0 -10
  75. data/generators/model/templates/fixtures.yml +0 -1
  76. data/generators/scaffold/USAGE +0 -27
  77. data/generators/scaffold/scaffold_generator.rb +0 -60
@@ -0,0 +1,30 @@
1
+ Description:
2
+ The controller generator creates stubs for a new controller and its views.
3
+
4
+ The generator takes a controller name and a list of views as arguments.
5
+ The controller name may be given in CamelCase or under_score and should
6
+ not be suffixed with 'Controller'. To create a controller within a
7
+ module, specify the controller name as 'module/controller'.
8
+
9
+ The generator creates a controller class in app/controllers with view
10
+ templates in app/views/controller_name, a helper class in app/helpers,
11
+ and a functional test suite in test/functional.
12
+
13
+ Example:
14
+ ./script/generate controller CreditCard open debit credit close
15
+
16
+ Credit card controller with URLs like /credit_card/debit.
17
+ Controller: app/controllers/credit_card_controller.rb
18
+ Views: app/views/credit_card/debit.rhtml [...]
19
+ Helper: app/helpers/credit_card_helper.rb
20
+ Test: test/functional/credit_card_controller_test.rb
21
+
22
+ Modules Example:
23
+ ./script/generate controller 'admin/credit_card' suspend late_fee
24
+
25
+ Credit card admin controller with URLs /admin/credit_card/suspend.
26
+ Controller: app/controllers/admin/credit_card_controller.rb
27
+ Views: app/views/admin/credit_card/debit.rhtml [...]
28
+ Helper: app/helpers/admin/credit_card_helper.rb
29
+ Test: test/functional/admin/credit_card_controller_test.rb
30
+
@@ -0,0 +1,37 @@
1
+ class ControllerGenerator < Rails::Generator::NamedBase
2
+ def manifest
3
+ record do |m|
4
+ # Check for class naming collisions.
5
+ m.class_collisions class_path, "#{class_name}Controller", "#{class_name}ControllerTest", "#{class_name}Helper"
6
+
7
+ # Controller, helper, views, and test directories.
8
+ m.directory File.join('app/controllers', class_path)
9
+ m.directory File.join('app/helpers', class_path)
10
+ m.directory File.join('app/views', class_path, file_name)
11
+ m.directory File.join('test/functional', class_path)
12
+
13
+ # Controller class, functional test, and helper class.
14
+ m.template 'controller.rb',
15
+ File.join('app/controllers',
16
+ class_path,
17
+ "#{file_name}_controller.rb")
18
+
19
+ m.template 'functional_test.rb',
20
+ File.join('test/functional',
21
+ class_path,
22
+ "#{file_name}_controller_test.rb")
23
+
24
+ m.template 'helper.rb',
25
+ File.join('app/helpers',
26
+ class_path,
27
+ "#{file_name}_helper.rb")
28
+
29
+ # View template for each action.
30
+ actions.each do |action|
31
+ m.template 'view.rhtml',
32
+ File.join('app/views', class_path, file_name, "#{action}.rhtml"),
33
+ :assigns => { :action => action }
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,4 +1,4 @@
1
- class <%= full_class_name %> < ApplicationController
1
+ class <%= class_name %>Controller < ApplicationController
2
2
  <% if options[:scaffold] -%>
3
3
  scaffold :<%= singular_name %>
4
4
  <% end -%>
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper'
2
+ require '<%= file_path %>_controller'
3
+
4
+ # Re-raise errors caught by the controller.
5
+ class <%= class_name %>Controller; def rescue_action(e) raise e end; end
6
+
7
+ class <%= class_name %>ControllerTest < Test::Unit::TestCase
8
+ def setup
9
+ @controller = <%= class_name %>Controller.new
10
+ @request = ActionController::TestRequest.new
11
+ @response = ActionController::TestResponse.new
12
+ end
13
+
14
+ # Replace this with your real tests.
15
+ def test_truth
16
+ assert true
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ Description:
2
+ The mailer generator creates stubs for a new mailer and its views.
3
+
4
+ The generator takes a mailer name and a list of views as arguments.
5
+ The mailer name may be given in CamelCase or under_score and should
6
+ not be suffixed with 'Mailer'.
7
+
8
+ The generator creates a mailer class in app/models with view templates
9
+ in app/views/mailer_name, and a test suite with fixtures in test/unit.
10
+
11
+ Example:
12
+ ./script/generate mailer Notifications signup forgot_password invoice
13
+
14
+ This will create a NotificationsMailer:
15
+ Mailer: app/models/notifications.rb
16
+ Views: app/views/notifications/signup.rhtml [...]
17
+ Test: test/unit/credit_card_controller_test.rb
18
+ Fixtures: test/fixtures/notifications/signup [...]
19
+
@@ -0,0 +1,32 @@
1
+ class MailerGenerator < Rails::Generator::NamedBase
2
+ def manifest
3
+ record do |m|
4
+ # Check for class naming collisions.
5
+ m.class_collisions class_path, class_name, "#{class_name}Test"
6
+
7
+ # Mailer, view, test, and fixture directories.
8
+ m.directory File.join('app/models', class_path)
9
+ m.directory File.join('app/views', class_path, file_name)
10
+ m.directory File.join('test/unit', class_path)
11
+ m.directory File.join('test/fixtures', class_path, table_name)
12
+
13
+ # Mailer class and unit test.
14
+ m.template "mailer.rb", File.join('app/models',
15
+ class_path,
16
+ "#{file_name}.rb")
17
+ m.template "unit_test.rb", File.join('test/unit',
18
+ class_path,
19
+ "#{file_name}_test.rb")
20
+
21
+ # View template and fixture for each action.
22
+ actions.each do |action|
23
+ m.template "view.rhtml",
24
+ File.join('app/views', class_path, file_name, "#{action}.rhtml"),
25
+ :assigns => { :action => action }
26
+ m.template "fixture.rhtml",
27
+ File.join('test/fixtures', class_path, table_name, action),
28
+ :assigns => { :action => action }
29
+ end
30
+ end
31
+ end
32
+ end
@@ -3,6 +3,7 @@ require '<%= file_name %>'
3
3
 
4
4
  class <%= class_name %>Test < Test::Unit::TestCase
5
5
  FIXTURES_PATH = File.dirname(__FILE__) + '/../fixtures'
6
+ CHARSET = "utf-8"
6
7
 
7
8
  def setup
8
9
  ActionMailer::Base.delivery_method = :test
@@ -10,11 +11,12 @@ class <%= class_name %>Test < Test::Unit::TestCase
10
11
  ActionMailer::Base.deliveries = []
11
12
 
12
13
  @expected = TMail::Mail.new
14
+ @expected.set_content_type "text", "plain", { "charset" => CHARSET }
13
15
  end
14
16
 
15
17
  <% for action in actions -%>
16
18
  def test_<%= action %>
17
- @expected.subject = '<%= class_name %>#<%= action %>'
19
+ @expected.subject = encode '<%= class_name %>#<%= action %>'
18
20
  @expected.body = read_fixture('<%= action %>')
19
21
  @expected.date = Time.now
20
22
 
@@ -26,4 +28,8 @@ class <%= class_name %>Test < Test::Unit::TestCase
26
28
  def read_fixture(action)
27
29
  IO.readlines("#{FIXTURES_PATH}/<%= file_name %>/#{action}")
28
30
  end
31
+
32
+ def encode(subject)
33
+ ActionMailer::Base.quoted_printable(subject, CHARSET)
34
+ end
29
35
  end
@@ -0,0 +1,17 @@
1
+ Description:
2
+ The model generator creates stubs for a new model.
3
+
4
+ The generator takes a model name as its argument. The model name may be
5
+ given in CamelCase or under_score and should not be suffixed with 'Model'.
6
+
7
+ The generator creates a model class in app/models, a test suite in
8
+ test/unit, and test fixtures in test/fixtures/model_name.yml.
9
+
10
+ Example:
11
+ ./script/generate model Account
12
+
13
+ This will create an Account model:
14
+ Model: app/models/account.rb
15
+ Test: test/unit/account_test.rb
16
+ Fixtures: test/fixtures/accounts.yml
17
+
@@ -0,0 +1,18 @@
1
+ class ModelGenerator < Rails::Generator::NamedBase
2
+ def manifest
3
+ record do |m|
4
+ # Check for class naming collisions.
5
+ m.class_collisions class_path, class_name, "#{class_name}Test"
6
+
7
+ # Model, test, and fixture directories.
8
+ m.directory File.join('app/models', class_path)
9
+ m.directory File.join('test/unit', class_path)
10
+ m.directory File.join('test/fixtures', class_path)
11
+
12
+ # Model class, unit test, and fixtures.
13
+ m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
14
+ m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb")
15
+ m.template 'fixtures.yml', File.join('test/fixtures', class_path, "#{table_name}.yml")
16
+ end
17
+ end
18
+ end
@@ -1,7 +1,5 @@
1
1
  # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
-
3
2
  first_<%= singular_name %>:
4
3
  id: 1
5
-
6
4
  another_<%= singular_name %>:
7
5
  id: 2
@@ -3,8 +3,12 @@ require File.dirname(__FILE__) + '/../test_helper'
3
3
  class <%= class_name %>Test < Test::Unit::TestCase
4
4
  fixtures :<%= table_name %>
5
5
 
6
+ def setup
7
+ @<%= singular_name %> = <%= class_name %>.find(1)
8
+ end
9
+
6
10
  # Replace this with your real tests.
7
11
  def test_truth
8
- assert true
12
+ assert_kind_of <%= class_name %>, @<%= singular_name %>
9
13
  end
10
14
  end
@@ -0,0 +1,32 @@
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 controller 'admin/credit_card' suspend late_fee
29
+
30
+ This will generate a CreditCard model and CreditCardController controller
31
+ in the admin module.
32
+
@@ -0,0 +1,178 @@
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
+ end
10
+
11
+ class ActionView::Helpers::InstanceTag
12
+ def to_input_field_tag(field_type, options={})
13
+ field_meth = "#{field_type}_field"
14
+ "<%= #{field_meth} '#{@object_name}', '#{@method_name}' #{options.empty? ? '' : ', '+options.inspect} %>"
15
+ end
16
+
17
+ def to_text_area_tag(options = {})
18
+ "<%= text_area '#{@object_name}', '#{@method_name}' #{options.empty? ? '' : ', '+ options.inspect} %>"
19
+ end
20
+
21
+ def to_date_select_tag(options = {})
22
+ "<%= date_select '#{@object_name}', '#{@method_name}' #{options.empty? ? '' : ', '+ options.inspect} %>"
23
+ end
24
+
25
+ def to_datetime_select_tag(options = {})
26
+ "<%= datetime_select '#{@object_name}', '#{@method_name}' #{options.empty? ? '' : ', '+ options.inspect} %>"
27
+ end
28
+ end
29
+
30
+ class ScaffoldGenerator < Rails::Generator::NamedBase
31
+ attr_reader :controller_name,
32
+ :controller_class_path,
33
+ :controller_file_path,
34
+ :controller_class_nesting,
35
+ :controller_class_nesting_depth,
36
+ :controller_class_name,
37
+ :controller_singular_name,
38
+ :controller_plural_name
39
+ alias_method :controller_file_name, :controller_singular_name
40
+ alias_method :controller_table_name, :controller_plural_name
41
+
42
+ def initialize(runtime_args, runtime_options = {})
43
+ super
44
+ @controller_name = args.shift || @name.pluralize
45
+ base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
46
+ @controller_class_name_without_nesting, @controller_singular_name, @controller_plural_name = inflect_names(base_name)
47
+ if @controller_class_nesting.empty?
48
+ @controller_class_name = @controller_class_name_without_nesting
49
+ else
50
+ @controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
51
+ end
52
+ end
53
+
54
+ def manifest
55
+ record do |m|
56
+ # Depend on model generator but skip if the model exists.
57
+ m.dependency 'model', [@name], :collision => :skip
58
+
59
+ # Check for class naming collisions.
60
+ m.class_collisions controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}ControllerTest", "#{controller_class_name}Helper"
61
+
62
+ # Controller, helper, views, and test directories.
63
+ m.directory File.join('app/controllers', controller_class_path)
64
+ m.directory File.join('app/helpers', controller_class_path)
65
+ m.directory File.join('app/views', controller_class_path, controller_file_name)
66
+ m.directory File.join('test/functional', controller_class_path)
67
+
68
+
69
+ # Controller class, functional test, helper, and views.
70
+ m.template 'controller.rb',
71
+ File.join('app/controllers',
72
+ controller_class_path,
73
+ "#{controller_file_name}_controller.rb")
74
+
75
+ m.template 'functional_test.rb',
76
+ File.join('test/functional',
77
+ controller_class_path,
78
+ "#{controller_file_name}_controller_test.rb")
79
+
80
+ m.template 'helper.rb',
81
+ File.join('app/helpers',
82
+ controller_class_path,
83
+ "#{controller_file_name}_helper.rb")
84
+
85
+ # Layout and stylesheet.
86
+ m.template 'layout.rhtml', "app/views/layouts/#{controller_file_name}.rhtml"
87
+ m.template 'style.css', 'public/stylesheets/scaffold.css'
88
+
89
+ # Scaffolded views.
90
+ scaffold_views.each do |action|
91
+ m.template "view_#{action}.rhtml",
92
+ File.join('app/views',
93
+ controller_class_path,
94
+ controller_file_name,
95
+ "#{action}.rhtml"),
96
+ :assigns => { :action => action }
97
+ end
98
+
99
+ # Scaffolded forms.
100
+ scaffold_forms.each do |action|
101
+ m.complex_template "view_#{action}.rhtml",
102
+ File.join('app/views',
103
+ controller_class_path,
104
+ controller_file_name,
105
+ "#{action}.rhtml"),
106
+ :assigns => { :action => action },
107
+ :insert => 'form.rhtml',
108
+ :sandbox => lambda { create_sandbox(action) },
109
+ :begin_mark => 'form',
110
+ :end_mark => 'eoform',
111
+ :mark_id => singular_name
112
+ end
113
+
114
+ # Unscaffolded views.
115
+ unscaffolded_actions.each do |action|
116
+ m.template "controller:view.rhtml",
117
+ File.join('app/views',
118
+ controller_class_path,
119
+ controller_file_name,
120
+ "#{action}.rhtml"),
121
+ :assigns => { :action => action }
122
+ end
123
+ end
124
+ end
125
+
126
+ protected
127
+ # Override with your own usage banner.
128
+ def banner
129
+ "Usage: #{$0} scaffold ModelName [ControllerName] [action, ...]"
130
+ end
131
+
132
+ def scaffold_views
133
+ %w(list show)
134
+ end
135
+
136
+ def scaffold_forms
137
+ %w(new edit)
138
+ end
139
+
140
+ def scaffold_actions
141
+ scaffold_views + %w(index create update destroy)
142
+ end
143
+
144
+ def unscaffolded_actions
145
+ args - scaffold_actions
146
+ end
147
+
148
+ def suffix
149
+ "_#{singular_name}" if options[:suffix]
150
+ end
151
+
152
+ def create_sandbox(action)
153
+ sandbox = ScaffoldingSandbox.new
154
+ action = if action == 'edit' then 'update' else 'create' end
155
+ sandbox.form_action = action
156
+ sandbox.singular_name = singular_name
157
+ begin
158
+ sandbox.model_instance = model_instance
159
+ sandbox.instance_variable_set("@#{singular_name}", sandbox.model_instance)
160
+ rescue ActiveRecord::StatementInvalid => e
161
+ logger.error "Before updating scaffolding from new DB schema, try creating a table for your model (#{class_name})"
162
+ raise SystemExit
163
+ end
164
+ sandbox.suffix = suffix
165
+ sandbox
166
+ end
167
+
168
+ def model_instance
169
+ base = class_nesting.split('::').inject(Object) do |base, nested|
170
+ break base.const_get(nested) if base.const_defined?(nested)
171
+ base.const_set(nested, Module.new)
172
+ end
173
+ unless base.const_defined?(@class_name_without_nesting)
174
+ base.const_set(@class_name_without_nesting, Class.new(ActiveRecord::Base))
175
+ end
176
+ class_name.constantize.new
177
+ end
178
+ end