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
@@ -1,196 +0,0 @@
1
- require 'breakpoint'
2
- require 'optparse'
3
- require 'timeout'
4
-
5
- Options = {
6
- :ClientURI => nil,
7
- :ServerURI => "druby://localhost:42531",
8
- :RetryDelay => 2,
9
- :Permanent => true,
10
- :Verbose => false
11
- }
12
-
13
- ARGV.options do |opts|
14
- script_name = File.basename($0)
15
- opts.banner = [
16
- "Usage: ruby #{script_name} [Options] [server uri]",
17
- "",
18
- "This tool lets you connect to a breakpoint service ",
19
- "which was started via Breakpoint.activate_drb.",
20
- "",
21
- "The server uri defaults to druby://localhost:42531"
22
- ].join("\n")
23
-
24
- opts.separator ""
25
-
26
- opts.on("-c", "--client-uri=uri",
27
- "Run the client on the specified uri.",
28
- "This can be used to specify the port",
29
- "that the client uses to allow for back",
30
- "connections from the server.",
31
- "Default: Find a good URI automatically.",
32
- "Example: -c druby://localhost:12345"
33
- ) { |v| Options[:ClientURI] = v }
34
-
35
- opts.on("-s", "--server-uri=uri",
36
- "Connect to the server specified at the",
37
- "specified uri.",
38
- "Default: druby://localhost:42531"
39
- ) { |v| Options[:ServerURI] = v }
40
-
41
- opts.on("-R", "--retry-delay=delay", Integer,
42
- "Automatically try to reconnect to the",
43
- "server after delay seconds when the",
44
- "connection failed or timed out.",
45
- "A value of 0 disables automatical",
46
- "reconnecting completely.",
47
- "Default: 10"
48
- ) { |v| Options[:RetryDelay] = v }
49
-
50
- opts.on("-P", "--[no-]permanent",
51
- "Run the breakpoint client in permanent mode.",
52
- "This means that the client will keep continue",
53
- "running even after the server has closed the",
54
- "connection. Useful for example in Rails."
55
- ) { |v| Options[:Permanent] = v }
56
-
57
- opts.on("-V", "--[no-]verbose",
58
- "Run the breakpoint client in verbose mode.",
59
- "Will produce more messages, for example between",
60
- "individual breakpoints. This might help in seeing",
61
- "that the breakpoint client is still alive, but adds",
62
- "quite a bit of clutter."
63
- ) { |v| Options[:Verbose] = v }
64
-
65
- opts.separator ""
66
-
67
- opts.on("-h", "--help",
68
- "Show this help message."
69
- ) { puts opts; exit }
70
- opts.on("-v", "--version",
71
- "Display the version information."
72
- ) do
73
- id = %q$Id: breakpoint_client.rb 91 2005-02-04 22:34:08Z flgr $
74
- puts id.sub("Id: ", "")
75
- puts "(Breakpoint::Version = #{Breakpoint::Version})"
76
- exit
77
- end
78
-
79
- opts.parse!
80
- end
81
-
82
- Options[:ServerURI] = ARGV[0] if ARGV[0]
83
-
84
- module Handlers #:nodoc:
85
- extend self
86
-
87
- def breakpoint_handler(workspace, message)
88
- puts message
89
- IRB.start(nil, nil, workspace)
90
-
91
- puts ""
92
- if Options[:Verbose] then
93
- puts "Resumed execution. Waiting for next breakpoint...", ""
94
- end
95
- end
96
-
97
- def eval_handler(code)
98
- result = eval(code, TOPLEVEL_BINDING)
99
- if result then
100
- DRbObject.new(result)
101
- else
102
- result
103
- end
104
- end
105
-
106
- def collision_handler()
107
- msg = [
108
- " *** Breakpoint service collision ***",
109
- " Another Breakpoint service tried to use the",
110
- " port already occupied by this one. It will",
111
- " keep waiting until this Breakpoint service",
112
- " is shut down.",
113
- " ",
114
- " If you are using the Breakpoint library for",
115
- " debugging a Rails or other CGI application",
116
- " this likely means that this Breakpoint",
117
- " session belongs to an earlier, outdated",
118
- " request and should be shut down via 'exit'."
119
- ].join("\n")
120
-
121
- if RUBY_PLATFORM["win"] then
122
- # This sucks. Sorry, I'm not doing this because
123
- # I like funky message boxes -- I need to do this
124
- # because on Windows I have no way of displaying
125
- # my notification via puts() when gets() is still
126
- # being performed on STDIN. I have not found a
127
- # better solution.
128
- begin
129
- require 'tk'
130
- root = TkRoot.new { withdraw }
131
- Tk.messageBox('message' => msg, 'type' => 'ok')
132
- root.destroy
133
- rescue Exception
134
- puts "", msg, ""
135
- end
136
- else
137
- puts "", msg, ""
138
- end
139
- end
140
- end
141
-
142
- # Used for checking whether we are currently in the reconnecting loop.
143
- reconnecting = false
144
-
145
- loop do
146
- DRb.start_service(Options[:ClientURI])
147
-
148
- begin
149
- service = DRbObject.new(nil, Options[:ServerURI])
150
-
151
- begin
152
- ehandler = Handlers.method(:eval_handler)
153
- chandler = Handlers.method(:collision_handler)
154
- handler = Handlers.method(:breakpoint_handler)
155
- service.eval_handler = ehandler
156
- service.collision_handler = chandler
157
- service.handler = handler
158
-
159
- reconnecting = false
160
- if Options[:Verbose] then
161
- puts "Connection established. Waiting for breakpoint...", ""
162
- end
163
-
164
- loop do
165
- begin
166
- service.ping
167
- rescue DRb::DRbConnError => error
168
- puts "Server exited. Closing connection...", ""
169
- exit! unless Options[:Permanent]
170
- break
171
- end
172
-
173
- sleep(0.5)
174
- end
175
- ensure
176
- service.eval_handler = nil
177
- service.collision_handler = nil
178
- service.handler = nil
179
- end
180
- rescue Exception => error
181
- if Options[:RetryDelay] > 0 then
182
- if not reconnecting then
183
- reconnecting = true
184
- puts "No connection to breakpoint service at #{Options[:ServerURI]} " +
185
- "(#{error.class})"
186
- puts error.backtrace if $DEBUG
187
- puts "Tries to connect will be made every #{Options[:RetryDelay]} seconds..."
188
- end
189
-
190
- sleep Options[:RetryDelay]
191
- retry
192
- else
193
- raise
194
- end
195
- end
196
- end
@@ -1 +0,0 @@
1
- require 'breakpoint_client'
@@ -1,18 +0,0 @@
1
- Description:
2
- The resource generator creates an empty model and controller for use in a REST-friendly, resource-oriented
3
- application. Say you want to a resource called post. Normally, you could just call "script/generate model post" and
4
- "script/generate controller posts". This generator basically just collapses these two generators into one step.
5
-
6
- The generator takes the name of the model as its first argument. This model name is then pluralized to get the
7
- controller name. So "resource post" will generate a Post model and a PostsController and will be intended
8
- for URLs like /posts and /posts/45.
9
-
10
- As additional parameters, the generator will take attribute pairs described by name and type. These attributes will
11
- be used to prepopulate the migration to create the table for the model and give you a set of predefined fixture.
12
- You don't have to think up all attributes up front, but it's a good idea of adding just the baseline of what's
13
- needed to start really working with the resource.
14
-
15
- Examples:
16
- ./script/generate resource post
17
- ./script/generate resource post title:string created_on:date body:text published:boolean
18
- ./script/generate resource purchase order_id:integer created_at:datetime amount:decimal
@@ -1,11 +0,0 @@
1
- # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
- one:
3
- id: 1
4
- <% for attribute in attributes -%>
5
- <%= attribute.name %>: <%= attribute.default %>
6
- <% end -%>
7
- two:
8
- id: 2
9
- <% for attribute in attributes -%>
10
- <%= attribute.name %>: <%= attribute.default %>
11
- <% end -%>
@@ -1,13 +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.column :<%= attribute.name %>, :<%= attribute.type %>
6
- <% end -%>
7
- end
8
- end
9
-
10
- def self.down
11
- drop_table :<%= table_name %>
12
- end
13
- end
@@ -1,2 +0,0 @@
1
- class <%= class_name %> < ActiveRecord::Base
2
- end
@@ -1,10 +0,0 @@
1
- require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper'
2
-
3
- class <%= class_name %>Test < Test::Unit::TestCase
4
- fixtures :<%= table_name %>
5
-
6
- # Replace this with your real tests.
7
- def test_truth
8
- assert true
9
- end
10
- end
@@ -1,3 +0,0 @@
1
- <%%= error_messages_for '<%= singular_name %>' %>
2
-
3
- <%= template_for_inclusion %>
@@ -1 +0,0 @@
1
- <%= all_input_tags(@model_instance, @singular_name, {}) %>
@@ -1,9 +0,0 @@
1
- <h1>Editing <%= singular_name %></h1>
2
-
3
- <%% form_tag :action => 'update<%= @suffix %>', :id => @<%= singular_name %> do %>
4
- <%%= render :partial => 'form' %>
5
- <%%= submit_tag 'Edit' %>
6
- <%% end %>
7
-
8
- <%%= link_to 'Show', :action => 'show<%= suffix %>', :id => @<%= singular_name %> %> |
9
- <%%= link_to 'Back', :action => 'list<%= suffix %>' %>
@@ -1,27 +0,0 @@
1
- <h1>Listing <%= plural_name %></h1>
2
-
3
- <table>
4
- <tr>
5
- <%% for column in <%= model_name %>.content_columns %>
6
- <th><%%= column.human_name %></th>
7
- <%% end %>
8
- </tr>
9
-
10
- <%% for <%= singular_name %> in @<%= plural_name %> %>
11
- <tr>
12
- <%% for column in <%= model_name %>.content_columns %>
13
- <td><%%=h <%= singular_name %>.send(column.name) %></td>
14
- <%% end %>
15
- <td><%%= link_to 'Show', :action => 'show<%= suffix %>', :id => <%= singular_name %> %></td>
16
- <td><%%= link_to 'Edit', :action => 'edit<%= suffix %>', :id => <%= singular_name %> %></td>
17
- <td><%%= link_to 'Destroy', { :action => 'destroy<%= suffix %>', :id => <%= singular_name %> }, :confirm => 'Are you sure?', :method => :post %></td>
18
- </tr>
19
- <%% end %>
20
- </table>
21
-
22
- <%%= link_to 'Previous page', { :page => @<%= singular_name %>_pages.current.previous } if @<%= singular_name %>_pages.current.previous %>
23
- <%%= link_to 'Next page', { :page => @<%= singular_name %>_pages.current.next } if @<%= singular_name %>_pages.current.next %>
24
-
25
- <br />
26
-
27
- <%%= link_to 'New <%= singular_name %>', :action => 'new<%= suffix %>' %>
@@ -1,8 +0,0 @@
1
- <h1>New <%= singular_name %></h1>
2
-
3
- <%% form_tag :action => 'create<%= @suffix %>' do %>
4
- <%%= render :partial => 'form' %>
5
- <%%= submit_tag "Create" %>
6
- <%% end %>
7
-
8
- <%%= link_to 'Back', :action => 'list<%= suffix %>' %>
@@ -1,8 +0,0 @@
1
- <%% for column in <%= model_name %>.content_columns %>
2
- <p>
3
- <b><%%= column.human_name %>:</b> <%%=h @<%= singular_name %>.send(column.name) %>
4
- </p>
5
- <%% end %>
6
-
7
- <%%= link_to 'Edit', :action => 'edit<%= suffix %>', :id => @<%= singular_name %> %> |
8
- <%%= link_to 'Back', :action => 'list<%= suffix %>' %>
@@ -1,29 +0,0 @@
1
- Description:
2
- The scaffold resource generator creates a model, a controller, and a set of templates that's ready to use as the
3
- starting point for your REST-like, resource-oriented application. This basically means that it follows a set of
4
- conventions to exploit the full set of HTTP verbs (GET/POST/PUT/DELETE) and is prepared for multi-client access
5
- (like one view for HTML, one for an XML API, one for ATOM, etc). Everything comes with sample unit and functional
6
- tests as well.
7
-
8
- The generator takes the name of the model as its first argument. This model name is then pluralized to get the
9
- controller name. So "scaffold_resource post" will generate a Post model and a PostsController and will be intended
10
- for URLs like /posts and /posts/45.
11
-
12
- As additional parameters, the generator will take attribute pairs described by name and type. These attributes will
13
- be used to prepopulate the migration to create the table for the model and to give you a set of templates for the
14
- view. For example, "scaffold_resource post title:string created_on:date body:text published:boolean" will give
15
- you a model with those four attributes, forms to create and edit those models from, and an index that'll list them
16
- all.
17
-
18
- You don't have to think up all attributes up front, but it's a good idea of adding just the baseline of what's
19
- needed to start really working with the resource.
20
-
21
- Once the generator has run, you'll need to add a declaration to your config/routes.rb file to hook up the rules
22
- that'll point URLs to this new resource. If you create a resource like "scaffold_resource post", you'll need to
23
- add "map.resources :posts" (notice the plural form) in the routes file. Then your new resource is accessible from
24
- /posts.
25
-
26
- Examples:
27
- ./script/generate scaffold_resource post # no attributes, view will be anemic
28
- ./script/generate scaffold_resource post title:string created_on:date body:text published:boolean
29
- ./script/generate scaffold_resource purchase order_id:integer created_at:datetime amount:decimal
@@ -1,93 +0,0 @@
1
- class ScaffoldResourceGenerator < Rails::Generator::NamedBase
2
- attr_reader :controller_name,
3
- :controller_class_path,
4
- :controller_file_path,
5
- :controller_class_nesting,
6
- :controller_class_nesting_depth,
7
- :controller_class_name,
8
- :controller_singular_name,
9
- :controller_plural_name
10
- alias_method :controller_file_name, :controller_singular_name
11
- alias_method :controller_table_name, :controller_plural_name
12
-
13
- def initialize(runtime_args, runtime_options = {})
14
- super
15
-
16
- @controller_name = @name.pluralize
17
-
18
- base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
19
- @controller_class_name_without_nesting, @controller_singular_name, @controller_plural_name = inflect_names(base_name)
20
-
21
- if @controller_class_nesting.empty?
22
- @controller_class_name = @controller_class_name_without_nesting
23
- else
24
- @controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
25
- end
26
- end
27
-
28
- def manifest
29
- record do |m|
30
- # Check for class naming collisions.
31
- m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
32
- m.class_collisions(class_path, "#{class_name}")
33
-
34
- # Controller, helper, views, and test directories.
35
- m.directory(File.join('app/models', class_path))
36
- m.directory(File.join('app/controllers', controller_class_path))
37
- m.directory(File.join('app/helpers', controller_class_path))
38
- m.directory(File.join('app/views', controller_class_path, controller_file_name))
39
- m.directory(File.join('app/views/layouts', controller_class_path))
40
- m.directory(File.join('test/functional', controller_class_path))
41
- m.directory(File.join('test/unit', class_path))
42
-
43
- for action in scaffold_views
44
- m.template(
45
- "view_#{action}.rhtml",
46
- File.join('app/views', controller_class_path, controller_file_name, "#{action}.rhtml")
47
- )
48
- end
49
-
50
- # Layout and stylesheet.
51
- m.template('layout.rhtml', File.join('app/views/layouts', controller_class_path, "#{controller_file_name}.rhtml"))
52
- m.template('style.css', 'public/stylesheets/scaffold.css')
53
-
54
- m.template('model.rb', File.join('app/models', class_path, "#{file_name}.rb"))
55
-
56
- m.template(
57
- 'controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
58
- )
59
-
60
- m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb"))
61
- m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb"))
62
- m.template('unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb"))
63
- m.template('fixtures.yml', File.join('test/fixtures', "#{table_name}.yml"))
64
-
65
- unless options[:skip_migration]
66
- m.migration_template(
67
- 'migration.rb', 'db/migrate',
68
- :assigns => {
69
- :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}",
70
- :attributes => attributes
71
- },
72
- :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
73
- )
74
- end
75
-
76
- m.route_resources controller_file_name
77
- end
78
- end
79
-
80
- protected
81
- # Override with your own usage banner.
82
- def banner
83
- "Usage: #{$0} scaffold_resource ModelName [field:type, field:type]"
84
- end
85
-
86
- def scaffold_views
87
- %w[ index show new edit ]
88
- end
89
-
90
- def model_name
91
- class_name.demodulize
92
- end
93
- end