railties 3.0.0.beta → 3.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (232) hide show
  1. data/CHANGELOG +15 -1
  2. data/README +9 -9
  3. data/bin/rails +28 -9
  4. data/guides/images/challenge.png +0 -0
  5. data/guides/images/edge_badge.png +0 -0
  6. data/guides/images/posts_index.png +0 -0
  7. data/guides/images/rails_welcome.png +0 -0
  8. data/guides/rails_guides.rb +9 -22
  9. data/guides/rails_guides/generator.rb +79 -50
  10. data/guides/rails_guides/textile_extensions.rb +3 -3
  11. data/guides/source/2_2_release_notes.textile +1 -1
  12. data/guides/source/2_3_release_notes.textile +1 -1
  13. data/guides/source/3_0_release_notes.textile +46 -38
  14. data/guides/source/action_controller_overview.textile +2 -2
  15. data/guides/source/action_mailer_basics.textile +4 -4
  16. data/guides/source/action_view_overview.textile +2 -2
  17. data/guides/source/active_record_querying.textile +73 -95
  18. data/guides/source/active_support_core_extensions.textile +993 -85
  19. data/guides/source/activerecord_validations_callbacks.textile +3 -3
  20. data/guides/source/caching_with_rails.textile +1 -1
  21. data/guides/source/command_line.textile +90 -88
  22. data/guides/source/configuring.textile +10 -10
  23. data/guides/source/contribute.textile +2 -2
  24. data/guides/source/contributing_to_rails.textile +14 -7
  25. data/guides/source/credits.textile.erb +8 -0
  26. data/guides/source/debugging_rails_applications.textile +6 -6
  27. data/guides/source/form_helpers.textile +1 -1
  28. data/guides/source/generators.textile +14 -14
  29. data/guides/source/getting_started.textile +634 -500
  30. data/guides/source/index.textile.erb +16 -1
  31. data/guides/source/layout.html.erb +7 -1
  32. data/guides/source/layouts_and_rendering.textile +299 -71
  33. data/guides/source/migrations.textile +5 -5
  34. data/guides/source/performance_testing.textile +8 -8
  35. data/guides/source/plugins.textile +26 -24
  36. data/guides/source/rails_on_rack.textile +5 -5
  37. data/guides/source/routing.textile +119 -117
  38. data/guides/source/security.textile +1 -1
  39. data/guides/source/testing.textile +4 -4
  40. data/lib/rails.rb +4 -1
  41. data/lib/rails/application.rb +44 -7
  42. data/lib/rails/application/bootstrap.rb +2 -14
  43. data/lib/rails/application/configuration.rb +69 -5
  44. data/lib/rails/application/finisher.rb +2 -3
  45. data/lib/rails/application/metal_loader.rb +1 -1
  46. data/lib/rails/application/routes_reloader.rb +1 -1
  47. data/lib/rails/backtrace_cleaner.rb +0 -11
  48. data/lib/rails/commands.rb +7 -6
  49. data/lib/rails/commands/application.rb +1 -1
  50. data/lib/rails/commands/console.rb +1 -1
  51. data/lib/rails/commands/dbconsole.rb +12 -0
  52. data/lib/rails/commands/destroy.rb +2 -2
  53. data/lib/rails/commands/generate.rb +2 -2
  54. data/lib/rails/commands/performance/benchmarker.rb +2 -2
  55. data/lib/rails/commands/performance/profiler.rb +2 -2
  56. data/lib/rails/commands/plugin.rb +6 -6
  57. data/lib/rails/commands/runner.rb +2 -0
  58. data/lib/rails/commands/server.rb +23 -8
  59. data/lib/rails/configuration.rb +2 -84
  60. data/lib/rails/console/app.rb +4 -3
  61. data/lib/rails/console/helpers.rb +3 -1
  62. data/lib/rails/engine.rb +107 -12
  63. data/lib/rails/engine/configuration.rb +8 -2
  64. data/lib/rails/generators.rb +22 -7
  65. data/lib/rails/generators/actions.rb +16 -6
  66. data/lib/rails/generators/base.rb +15 -8
  67. data/lib/rails/generators/erb.rb +21 -0
  68. data/lib/{generators → rails/generators}/erb/controller/controller_generator.rb +4 -5
  69. data/lib/{generators → rails/generators}/erb/controller/templates/view.html.erb +0 -0
  70. data/lib/rails/generators/erb/mailer/mailer_generator.rb +13 -0
  71. data/lib/{generators → rails/generators}/erb/mailer/templates/view.text.erb +0 -0
  72. data/lib/{generators → rails/generators}/erb/scaffold/scaffold_generator.rb +14 -26
  73. data/lib/{generators → rails/generators}/erb/scaffold/templates/_form.html.erb +1 -1
  74. data/lib/{generators → rails/generators}/erb/scaffold/templates/edit.html.erb +0 -0
  75. data/lib/{generators → rails/generators}/erb/scaffold/templates/index.html.erb +1 -1
  76. data/lib/{generators → rails/generators}/erb/scaffold/templates/layout.html.erb +1 -0
  77. data/lib/{generators → rails/generators}/erb/scaffold/templates/new.html.erb +0 -0
  78. data/lib/{generators → rails/generators}/erb/scaffold/templates/show.html.erb +0 -0
  79. data/lib/rails/generators/named_base.rb +4 -0
  80. data/lib/{generators → rails/generators}/rails/app/USAGE +0 -0
  81. data/lib/{generators → rails/generators}/rails/app/app_generator.rb +21 -7
  82. data/lib/rails/generators/rails/app/templates/Gemfile +34 -0
  83. data/lib/{generators → rails/generators}/rails/app/templates/README +9 -8
  84. data/lib/{generators → rails/generators}/rails/app/templates/Rakefile +0 -0
  85. data/lib/{generators → rails/generators}/rails/app/templates/app/controllers/application_controller.rb +0 -0
  86. data/lib/{generators → rails/generators}/rails/app/templates/app/helpers/application_helper.rb +0 -0
  87. data/lib/{generators → rails/generators}/rails/app/templates/app/models/.empty_directory +0 -0
  88. data/lib/{generators → rails/generators}/rails/app/templates/app/views/layouts/.empty_directory +0 -0
  89. data/lib/{generators → rails/generators}/rails/app/templates/config.ru +0 -0
  90. data/lib/{generators → rails/generators}/rails/app/templates/config/application.rb +4 -3
  91. data/lib/rails/generators/rails/app/templates/config/boot.rb +14 -0
  92. data/lib/{generators → rails/generators}/rails/app/templates/config/databases/frontbase.yml +0 -0
  93. data/lib/{generators → rails/generators}/rails/app/templates/config/databases/ibm_db.yml +0 -0
  94. data/lib/{generators → rails/generators}/rails/app/templates/config/databases/mysql.yml +0 -0
  95. data/lib/{generators → rails/generators}/rails/app/templates/config/databases/oracle.yml +0 -0
  96. data/lib/{generators → rails/generators}/rails/app/templates/config/databases/postgresql.yml +0 -0
  97. data/lib/{generators → rails/generators}/rails/app/templates/config/databases/sqlite3.yml +0 -0
  98. data/lib/{generators → rails/generators}/rails/app/templates/config/environment.rb +0 -0
  99. data/lib/{generators → rails/generators}/rails/app/templates/config/environments/development.rb.tt +0 -0
  100. data/lib/{generators → rails/generators}/rails/app/templates/config/environments/production.rb.tt +9 -0
  101. data/lib/{generators → rails/generators}/rails/app/templates/config/environments/test.rb.tt +0 -0
  102. data/lib/{generators → rails/generators}/rails/app/templates/config/initializers/backtrace_silencers.rb +0 -0
  103. data/lib/{generators → rails/generators}/rails/app/templates/config/initializers/cookie_verification_secret.rb.tt +1 -1
  104. data/lib/{generators → rails/generators}/rails/app/templates/config/initializers/inflections.rb +0 -0
  105. data/lib/{generators → rails/generators}/rails/app/templates/config/initializers/mime_types.rb +0 -0
  106. data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +10 -0
  107. data/lib/{generators → rails/generators}/rails/app/templates/config/locales/en.yml +0 -0
  108. data/lib/{generators → rails/generators}/rails/app/templates/config/routes.rb +0 -0
  109. data/lib/{generators → rails/generators}/rails/app/templates/db/seeds.rb +0 -0
  110. data/lib/{generators → rails/generators}/rails/app/templates/doc/README_FOR_APP +0 -0
  111. data/lib/{generators → rails/generators}/rails/app/templates/gitignore +0 -0
  112. data/lib/{generators → rails/generators}/rails/app/templates/public/404.html +0 -0
  113. data/lib/{generators → rails/generators}/rails/app/templates/public/422.html +0 -0
  114. data/lib/{generators → rails/generators}/rails/app/templates/public/500.html +0 -0
  115. data/lib/{generators → rails/generators}/rails/app/templates/public/favicon.ico +0 -0
  116. data/lib/{generators → rails/generators}/rails/app/templates/public/images/rails.png +0 -0
  117. data/lib/{generators → rails/generators}/rails/app/templates/public/index.html +17 -17
  118. data/lib/{generators → rails/generators}/rails/app/templates/public/javascripts/application.js +0 -0
  119. data/lib/{generators → rails/generators}/rails/app/templates/public/javascripts/controls.js +5 -3
  120. data/lib/{generators → rails/generators}/rails/app/templates/public/javascripts/dragdrop.js +7 -6
  121. data/lib/{generators → rails/generators}/rails/app/templates/public/javascripts/effects.js +8 -13
  122. data/lib/{generators → rails/generators}/rails/app/templates/public/javascripts/prototype.js +1573 -1019
  123. data/lib/{generators → rails/generators}/rails/app/templates/public/javascripts/rails.js +1 -2
  124. data/lib/{generators → rails/generators}/rails/app/templates/public/robots.txt +0 -0
  125. data/lib/{generators → rails/generators}/rails/app/templates/public/stylesheets/.empty_directory +0 -0
  126. data/lib/{generators → rails/generators}/rails/app/templates/script/rails +0 -1
  127. data/lib/{generators → rails/generators}/rails/app/templates/test/fixtures/.empty_directory +0 -0
  128. data/lib/{generators → rails/generators}/rails/app/templates/test/functional/.empty_directory +0 -0
  129. data/lib/{generators → rails/generators}/rails/app/templates/test/integration/.empty_directory +0 -0
  130. data/lib/{generators → rails/generators}/rails/app/templates/test/performance/browsing_test.rb +1 -1
  131. data/lib/{generators → rails/generators}/rails/app/templates/test/test_helper.rb +1 -1
  132. data/lib/{generators → rails/generators}/rails/app/templates/test/unit/.empty_directory +0 -0
  133. data/lib/{generators → rails/generators}/rails/controller/USAGE +1 -1
  134. data/lib/{generators → rails/generators}/rails/controller/controller_generator.rb +6 -0
  135. data/lib/{generators → rails/generators}/rails/controller/templates/controller.rb +0 -0
  136. data/lib/{generators → rails/generators}/rails/generator/USAGE +1 -1
  137. data/lib/{generators → rails/generators}/rails/generator/generator_generator.rb +0 -0
  138. data/lib/{generators → rails/generators}/rails/generator/templates/%file_name%_generator.rb.tt +0 -0
  139. data/lib/{generators → rails/generators}/rails/generator/templates/USAGE.tt +1 -1
  140. data/lib/{generators → rails/generators}/rails/generator/templates/templates/.empty_directory +0 -0
  141. data/lib/{generators → rails/generators}/rails/helper/USAGE +1 -1
  142. data/lib/{generators → rails/generators}/rails/helper/helper_generator.rb +0 -0
  143. data/lib/{generators → rails/generators}/rails/helper/templates/helper.rb +0 -0
  144. data/lib/{generators → rails/generators}/rails/integration_test/USAGE +1 -1
  145. data/lib/{generators → rails/generators}/rails/integration_test/integration_test_generator.rb +0 -0
  146. data/lib/{generators → rails/generators}/rails/mailer/USAGE +1 -1
  147. data/lib/{generators → rails/generators}/rails/mailer/mailer_generator.rb +0 -0
  148. data/lib/{generators → rails/generators}/rails/mailer/templates/mailer.rb +0 -0
  149. data/lib/{generators → rails/generators}/rails/metal/USAGE +1 -1
  150. data/lib/{generators → rails/generators}/rails/metal/metal_generator.rb +0 -0
  151. data/lib/{generators → rails/generators}/rails/metal/templates/metal.rb +0 -0
  152. data/lib/{generators → rails/generators}/rails/migration/USAGE +2 -2
  153. data/lib/{generators → rails/generators}/rails/migration/migration_generator.rb +0 -0
  154. data/lib/{generators → rails/generators}/rails/model/USAGE +2 -2
  155. data/lib/{generators → rails/generators}/rails/model/model_generator.rb +0 -0
  156. data/lib/{generators → rails/generators}/rails/observer/USAGE +1 -1
  157. data/lib/{generators → rails/generators}/rails/observer/observer_generator.rb +0 -0
  158. data/lib/{generators → rails/generators}/rails/performance_test/USAGE +1 -1
  159. data/lib/{generators → rails/generators}/rails/performance_test/performance_test_generator.rb +0 -0
  160. data/lib/{generators → rails/generators}/rails/plugin/USAGE +1 -1
  161. data/lib/{generators → rails/generators}/rails/plugin/plugin_generator.rb +1 -1
  162. data/lib/{generators → rails/generators}/rails/plugin/templates/MIT-LICENSE.tt +0 -0
  163. data/lib/{generators → rails/generators}/rails/plugin/templates/README.tt +0 -0
  164. data/lib/rails/generators/rails/plugin/templates/Rakefile.tt +23 -0
  165. data/lib/{generators → rails/generators}/rails/plugin/templates/init.rb +0 -0
  166. data/lib/{generators → rails/generators}/rails/plugin/templates/install.rb +0 -0
  167. data/lib/{generators → rails/generators}/rails/plugin/templates/lib/%file_name%.rb.tt +0 -0
  168. data/lib/{generators → rails/generators}/rails/plugin/templates/lib/tasks/%file_name%_tasks.rake.tt +0 -0
  169. data/lib/{generators → rails/generators}/rails/plugin/templates/uninstall.rb +0 -0
  170. data/lib/{generators → rails/generators}/rails/resource/USAGE +3 -3
  171. data/lib/{generators → rails/generators}/rails/resource/resource_generator.rb +3 -1
  172. data/lib/{generators → rails/generators}/rails/scaffold/USAGE +4 -4
  173. data/lib/{generators → rails/generators}/rails/scaffold/scaffold_generator.rb +1 -1
  174. data/lib/{generators → rails/generators}/rails/scaffold_controller/USAGE +1 -1
  175. data/lib/{generators → rails/generators}/rails/scaffold_controller/scaffold_controller_generator.rb +0 -0
  176. data/lib/{generators → rails/generators}/rails/scaffold_controller/templates/controller.rb +2 -2
  177. data/lib/{generators → rails/generators}/rails/session_migration/USAGE +1 -1
  178. data/lib/{generators → rails/generators}/rails/session_migration/session_migration_generator.rb +0 -0
  179. data/lib/{generators → rails/generators}/rails/stylesheets/USAGE +1 -1
  180. data/lib/{generators → rails/generators}/rails/stylesheets/stylesheets_generator.rb +0 -0
  181. data/lib/{generators → rails/generators}/rails/stylesheets/templates/scaffold.css +4 -0
  182. data/lib/{generators → rails/generators}/test_unit.rb +0 -0
  183. data/lib/{generators → rails/generators}/test_unit/controller/controller_generator.rb +2 -1
  184. data/lib/rails/generators/test_unit/controller/templates/functional_test.rb +18 -0
  185. data/lib/{generators → rails/generators}/test_unit/helper/helper_generator.rb +1 -1
  186. data/lib/{generators → rails/generators}/test_unit/helper/templates/helper_test.rb +0 -0
  187. data/lib/{generators → rails/generators}/test_unit/integration/integration_generator.rb +1 -1
  188. data/lib/{generators → rails/generators}/test_unit/integration/templates/integration_test.rb +0 -0
  189. data/lib/{generators → rails/generators}/test_unit/mailer/mailer_generator.rb +1 -8
  190. data/lib/rails/generators/test_unit/mailer/templates/functional_test.rb +20 -0
  191. data/lib/{generators → rails/generators}/test_unit/model/model_generator.rb +1 -1
  192. data/lib/{generators → rails/generators}/test_unit/model/templates/fixtures.yml +0 -0
  193. data/lib/{generators → rails/generators}/test_unit/model/templates/unit_test.rb +0 -0
  194. data/lib/{generators → rails/generators}/test_unit/observer/observer_generator.rb +1 -1
  195. data/lib/{generators → rails/generators}/test_unit/observer/templates/unit_test.rb +0 -0
  196. data/lib/{generators → rails/generators}/test_unit/performance/performance_generator.rb +1 -1
  197. data/lib/{generators → rails/generators}/test_unit/performance/templates/performance_test.rb +0 -0
  198. data/lib/{generators → rails/generators}/test_unit/plugin/plugin_generator.rb +1 -1
  199. data/lib/{generators → rails/generators}/test_unit/plugin/templates/%file_name%_test.rb.tt +0 -0
  200. data/lib/{generators → rails/generators}/test_unit/plugin/templates/test_helper.rb +0 -0
  201. data/lib/{generators → rails/generators}/test_unit/scaffold/scaffold_generator.rb +1 -1
  202. data/lib/{generators → rails/generators}/test_unit/scaffold/templates/functional_test.rb +9 -5
  203. data/{builtin/rails_info → lib}/rails/info.rb +0 -0
  204. data/{builtin/rails_info → lib}/rails/info_controller.rb +0 -0
  205. data/{builtin/routes.rb → lib/rails/info_routes.rb} +2 -2
  206. data/lib/rails/{subscriber.rb → log_subscriber.rb} +27 -27
  207. data/lib/rails/{subscriber → log_subscriber}/test_helper.rb +15 -16
  208. data/lib/rails/plugin.rb +31 -8
  209. data/lib/rails/rack/debugger.rb +3 -1
  210. data/lib/rails/rack/logger.rb +4 -4
  211. data/lib/rails/railtie.rb +179 -16
  212. data/lib/rails/railtie/configuration.rb +56 -1
  213. data/lib/rails/tasks/documentation.rake +38 -20
  214. data/lib/rails/tasks/framework.rake +16 -9
  215. data/lib/rails/tasks/misc.rake +3 -5
  216. data/lib/rails/tasks/routes.rake +2 -2
  217. data/lib/rails/test_help.rb +21 -1
  218. data/lib/rails/test_unit/railtie.rb +1 -3
  219. data/lib/rails/version.rb +3 -2
  220. metadata +199 -171
  221. data/builtin/rails_info/rails/info_helper.rb +0 -2
  222. data/lib/generators/erb.rb +0 -8
  223. data/lib/generators/erb/mailer/mailer_generator.rb +0 -20
  224. data/lib/generators/rails/app/templates/Gemfile +0 -34
  225. data/lib/generators/rails/app/templates/config/boot.rb +0 -17
  226. data/lib/generators/rails/app/templates/config/initializers/session_store.rb.tt +0 -15
  227. data/lib/generators/rails/model_subclass/model_subclass_generator.rb +0 -12
  228. data/lib/generators/rails/plugin/templates/Rakefile.tt +0 -10
  229. data/lib/generators/test_unit/controller/templates/functional_test.rb +0 -8
  230. data/lib/generators/test_unit/mailer/templates/fixture +0 -3
  231. data/lib/generators/test_unit/mailer/templates/functional_test.rb +0 -22
  232. data/lib/rails/railties_path.rb +0 -1
@@ -32,7 +32,7 @@ module Rails
32
32
  options[:git] = "-b #{options[:branch]} #{options[:git]}" if options[:branch]
33
33
  options[:svn] = "-r #{options[:revision]} #{options[:svn]}" if options[:revision]
34
34
  in_root do
35
- run_ruby_script "script/plugin install #{options[:svn] || options[:git]}", :verbose => false
35
+ run_ruby_script "script/rails plugin install #{options[:svn] || options[:git]}", :verbose => false
36
36
  end
37
37
  else
38
38
  log "! no git or svn provided for #{name}. Skipping..."
@@ -69,7 +69,7 @@ module Rails
69
69
  # otherwise use name (version).
70
70
  parts, message = [ name.inspect ], name
71
71
  if version ||= options.delete(:version)
72
- parts << version
72
+ parts << version.inspect
73
73
  message << " (#{version})"
74
74
  end
75
75
  message = options[:git] if options[:git]
@@ -81,7 +81,7 @@ module Rails
81
81
  end
82
82
 
83
83
  in_root do
84
- append_file "Gemfile", "gem #{parts.join(", ")}", :verbose => false
84
+ append_file "Gemfile", "gem #{parts.join(", ")}\n", :verbose => false
85
85
  end
86
86
  end
87
87
 
@@ -89,12 +89,12 @@ module Rails
89
89
  #
90
90
  # ==== Example
91
91
  #
92
- # source "http://gems.github.com/"
92
+ # add_source "http://gems.github.com/"
93
93
  def add_source(source, options={})
94
94
  log :source, source
95
95
 
96
96
  in_root do
97
- prepend_file "Gemfile", "source #{source.inspect}", :verbose => false
97
+ prepend_file "Gemfile", "source #{source.inspect}\n", :verbose => false
98
98
  end
99
99
  end
100
100
 
@@ -226,7 +226,7 @@ module Rails
226
226
  log :generate, what
227
227
  argument = args.map {|arg| arg.to_s }.flatten.join(" ")
228
228
 
229
- in_root { run_ruby_script("script/generate #{what} #{argument}", :verbose => false) }
229
+ in_root { run_ruby_script("script/rails generate #{what} #{argument}", :verbose => false) }
230
230
  end
231
231
 
232
232
  # Runs the supplied rake task
@@ -280,6 +280,16 @@ module Rails
280
280
  end
281
281
  end
282
282
 
283
+ # Reads the given file at the source root and prints it in the console.
284
+ #
285
+ # === Example
286
+ #
287
+ # readme "README"
288
+ #
289
+ def readme(path)
290
+ say File.read(find_in_source_paths(path))
291
+ end
292
+
283
293
  protected
284
294
 
285
295
  # Define log for backwards compatibility. If just one argument is sent,
@@ -1,4 +1,12 @@
1
- require 'thor/group'
1
+ begin
2
+ require 'thor/group'
3
+ rescue LoadError
4
+ puts "Thor is not available.\nIf you ran this command from a git checkout " \
5
+ "of Rails, please make sure thor is installed,\nand run this command " \
6
+ "as `ruby /path/to/rails myapp --dev`"
7
+ exit
8
+ end
9
+
2
10
  require 'rails/generators/actions'
3
11
 
4
12
  module Rails
@@ -17,7 +25,7 @@ module Rails
17
25
  def self.source_root
18
26
  @_rails_source_root ||= begin
19
27
  if base_name && generator_name
20
- File.expand_path(File.join("../../generators", base_name, generator_name, 'templates'), File.dirname(__FILE__))
28
+ File.expand_path(File.join(base_name, generator_name, 'templates'), File.dirname(__FILE__))
21
29
  end
22
30
  end
23
31
  end
@@ -62,7 +70,7 @@ module Rails
62
70
  #
63
71
  # For example, if the user invoke the controller generator as:
64
72
  #
65
- # ruby script/generate controller Account --test-framework=test_unit
73
+ # rails generate controller Account --test-framework=test_unit
66
74
  #
67
75
  # The controller generator will then try to invoke the following generators:
68
76
  #
@@ -117,11 +125,11 @@ module Rails
117
125
  # All hooks come with switches for user interface. If the user don't want
118
126
  # to use any test framework, he can do:
119
127
  #
120
- # ruby script/generate controller Account --skip-test-framework
128
+ # rails generate controller Account --skip-test-framework
121
129
  #
122
130
  # Or similarly:
123
131
  #
124
- # ruby script/generate controller Account --no-test-framework
132
+ # rails generate controller Account --no-test-framework
125
133
  #
126
134
  # ==== Boolean hooks
127
135
  #
@@ -133,7 +141,7 @@ module Rails
133
141
  #
134
142
  # Then, if you want, webrat to be invoked, just supply:
135
143
  #
136
- # ruby script/generate controller Account --webrat
144
+ # rails generate controller Account --webrat
137
145
  #
138
146
  # The hooks lookup is similar as above:
139
147
  #
@@ -213,8 +221,7 @@ module Rails
213
221
  if base.name && base.name !~ /Base$/
214
222
  Rails::Generators.subclasses << base
215
223
 
216
- if defined?(Rails.root) && Rails.root
217
- path = File.expand_path(File.join(Rails.root, 'lib', 'templates'))
224
+ Rails::Generators.templates_path.each do |path|
218
225
  if base.name.include?('::')
219
226
  base.source_paths << File.join(path, base.base_name, base.generator_name)
220
227
  else
@@ -0,0 +1,21 @@
1
+ require 'rails/generators/named_base'
2
+
3
+ module Erb
4
+ module Generators
5
+ class Base < Rails::Generators::NamedBase #:nodoc:
6
+ protected
7
+
8
+ def format
9
+ :html
10
+ end
11
+
12
+ def handler
13
+ :erb
14
+ end
15
+
16
+ def filename_with_extensions(name)
17
+ [name, format, handler].compact.join(".")
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,19 +1,18 @@
1
- require 'generators/erb'
1
+ require 'rails/generators/erb'
2
2
 
3
3
  module Erb
4
4
  module Generators
5
5
  class ControllerGenerator < Base
6
6
  argument :actions, :type => :array, :default => [], :banner => "action action"
7
7
 
8
- def create_view_files
8
+ def copy_view_files
9
9
  base_path = File.join("app/views", class_path, file_name)
10
10
  empty_directory base_path
11
11
 
12
12
  actions.each do |action|
13
13
  @action = action
14
- @path = File.join(base_path, "#{action}.html.erb")
15
-
16
- template 'view.html.erb', @path
14
+ @path = File.join(base_path, filename_with_extensions(action))
15
+ template filename_with_extensions(:view), @path
17
16
  end
18
17
  end
19
18
  end
@@ -0,0 +1,13 @@
1
+ require 'rails/generators/erb/controller/controller_generator'
2
+
3
+ module Erb
4
+ module Generators
5
+ class MailerGenerator < ControllerGenerator
6
+ protected
7
+
8
+ def format
9
+ :text
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,4 +1,4 @@
1
- require 'generators/erb'
1
+ require 'rails/generators/erb'
2
2
  require 'rails/generators/resource_helpers'
3
3
 
4
4
  module Erb
@@ -15,39 +15,27 @@ module Erb
15
15
  empty_directory File.join("app/views", controller_file_path)
16
16
  end
17
17
 
18
- def copy_index_file
19
- return if options[:singleton]
20
- copy_view :index
21
- end
22
-
23
- def copy_edit_file
24
- copy_view :edit
25
- end
18
+ def copy_view_files
19
+ views = available_views
20
+ views.delete("index") if options[:singleton]
26
21
 
27
- def copy_show_file
28
- copy_view :show
29
- end
30
-
31
- def copy_new_file
32
- copy_view :new
33
- end
34
-
35
- def copy_form_file
36
- copy_view :_form
22
+ views.each do |view|
23
+ filename = filename_with_extensions(view)
24
+ template filename, File.join("app/views", controller_file_path, filename)
25
+ end
37
26
  end
38
27
 
39
28
  def copy_layout_file
40
29
  return unless options[:layout]
41
- template "layout.html.erb",
42
- File.join("app/views/layouts", controller_class_path, "#{controller_file_name}.html.erb")
30
+ template filename_with_extensions(:layout),
31
+ File.join("app/views/layouts", controller_class_path, filename_with_extensions(controller_file_name))
43
32
  end
44
33
 
45
- protected
46
-
47
- def copy_view(view)
48
- template "#{view}.html.erb", File.join("app/views", controller_file_path, "#{view}.html.erb")
49
- end
34
+ protected
50
35
 
36
+ def available_views
37
+ %w(index edit show new _form)
38
+ end
51
39
  end
52
40
  end
53
41
  end
@@ -1,4 +1,4 @@
1
- <%% form_for(@<%= singular_name %>) do |f| %>
1
+ <%%= form_for(@<%= singular_name %>) do |f| %>
2
2
  <%%= f.error_messages %>
3
3
 
4
4
  <% for attribute in attributes -%>
@@ -24,4 +24,4 @@
24
24
 
25
25
  <br />
26
26
 
27
- <%%= link_to 'New <%= singular_name %>', new_<%= singular_name %>_path %>
27
+ <%%= link_to 'New <%= human_name %>', new_<%= singular_name %>_path %>
@@ -9,6 +9,7 @@
9
9
  <body>
10
10
 
11
11
  <p class="notice"><%%= notice %></p>
12
+ <p class="alert"><%%= alert %></p>
12
13
 
13
14
  <%%= yield %>
14
15
 
@@ -27,6 +27,10 @@ module Rails
27
27
  @class_name ||= (class_path + [file_name]).map!{ |m| m.camelize }.join('::')
28
28
  end
29
29
 
30
+ def human_name
31
+ @human_name ||= singular_name.humanize
32
+ end
33
+
30
34
  def plural_name
31
35
  @plural_name ||= singular_name.pluralize
32
36
  end
@@ -5,7 +5,11 @@ require 'rails/version' unless defined?(Rails::VERSION)
5
5
  module Rails::Generators
6
6
  # We need to store the RAILS_DEV_PATH in a constant, otherwise the path
7
7
  # can change in Ruby 1.8.7 when we FileUtils.cd.
8
- RAILS_DEV_PATH = File.expand_path("../../../../..", File.dirname(__FILE__))
8
+ RAILS_DEV_PATH = File.expand_path("../../../../../..", File.dirname(__FILE__))
9
+
10
+ RESERVED_NAMES = %w[generate console server dbconsole
11
+ application destroy benchmarker profiler
12
+ plugin runner test]
9
13
 
10
14
  class AppGenerator < Base
11
15
  DATABASES = %w( mysql oracle postgresql sqlite3 frontbase ibm_db )
@@ -27,6 +31,9 @@ module Rails::Generators
27
31
  class_option :edge, :type => :boolean, :default => false,
28
32
  :desc => "Setup the application with Gemfile pointing to Rails repository"
29
33
 
34
+ class_option :skip_gemfile, :type => :boolean, :default => false,
35
+ :desc => "Don't create a Gemfile"
36
+
30
37
  class_option :skip_activerecord, :type => :boolean, :aliases => "-O", :default => false,
31
38
  :desc => "Skip ActiveRecord files"
32
39
 
@@ -67,7 +74,7 @@ module Rails::Generators
67
74
  copy_file "gitignore", ".gitignore" unless options[:skip_git]
68
75
  template "Rakefile"
69
76
  template "config.ru"
70
- template "Gemfile"
77
+ template "Gemfile" unless options[:skip_gemfile]
71
78
  end
72
79
 
73
80
  def create_app_files
@@ -134,8 +141,11 @@ module Rails::Generators
134
141
  end
135
142
 
136
143
  def create_prototype_files
137
- return if options[:skip_prototype]
138
- directory "public/javascripts"
144
+ unless options[:skip_prototype]
145
+ directory "public/javascripts"
146
+ else
147
+ empty_directory_with_gitkeep "public/javascripts"
148
+ end
139
149
  end
140
150
 
141
151
  def create_script_files
@@ -171,7 +181,8 @@ module Rails::Generators
171
181
  end
172
182
 
173
183
  def bundle_if_dev_or_edge
174
- run "bundle install" if dev_or_edge?
184
+ bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle')
185
+ run "#{bundle_command} install" if dev_or_edge?
175
186
  end
176
187
 
177
188
  protected
@@ -209,9 +220,12 @@ module Rails::Generators
209
220
  end
210
221
 
211
222
  def valid_app_const?
212
- case app_const
213
- when /^\d/
223
+ if app_const =~ /^\d/
214
224
  raise Error, "Invalid application name #{app_name}. Please give a name which does not start with numbers."
225
+ elsif RESERVED_NAMES.include?(app_name)
226
+ raise Error, "Invalid application name #{app_name}. Please give a name which does not match one of the reserved rails words."
227
+ elsif Object.const_defined?(app_const_base)
228
+ raise Error, "Invalid application name #{app_name}, constant #{app_const_base} is already in use. Please choose another application name."
215
229
  end
216
230
  end
217
231
 
@@ -0,0 +1,34 @@
1
+ source 'http://rubygems.org'
2
+
3
+ <%- if options.dev? -%>
4
+ gem 'rails', :path => '<%= Rails::Generators::RAILS_DEV_PATH %>'
5
+ <%- elsif options.edge? -%>
6
+ gem 'rails', :git => 'git://github.com/rails/rails.git'
7
+ <%- else -%>
8
+ gem 'rails', '<%= Rails::VERSION::STRING %>'
9
+
10
+ # Bundle edge Rails instead:
11
+ # gem 'rails', :git => 'git://github.com/rails/rails.git'
12
+ <%- end -%>
13
+
14
+ <% unless options[:skip_activerecord] -%>
15
+ gem '<%= gem_for_database %>'<% if require_for_database %>, :require => '<%= require_for_database %>'<% end %>
16
+ <% end -%>
17
+
18
+ # Use unicorn as the web server
19
+ # gem 'unicorn'
20
+
21
+ # Deploy with Capistrano
22
+ # gem 'capistrano'
23
+
24
+ # Bundle the extra gems:
25
+ # gem 'bj'
26
+ # gem 'nokogiri', '1.4.1'
27
+ # gem 'sqlite3-ruby', :require => 'sqlite3'
28
+ # gem 'aws-s3', :require => 'aws/s3'
29
+
30
+ # Bundle gems for certain environments:
31
+ # gem 'rspec', :group => :test
32
+ # group :test do
33
+ # gem 'webrat'
34
+ # end
@@ -29,14 +29,15 @@ link:files/vendor/rails/actionpack/README.html.
29
29
 
30
30
  1. At the command prompt, start a new Rails application using the <tt>rails</tt> command
31
31
  and your application name. Ex: rails myapp
32
- 2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
32
+ 2. Change directory into myapp and start the web server: <tt>rails server</tt> (run with --help for options)
33
33
  3. Go to http://localhost:3000/ and get "Welcome aboard: You're riding the Rails!"
34
34
  4. Follow the guidelines to start developing your application
35
35
 
36
36
 
37
37
  == Web Servers
38
38
 
39
- By default, Rails will try to use Mongrel if it's are installed when started with script/server, otherwise Rails will use WEBrick, the webserver that ships with Ruby. But you can also use Rails
39
+ By default, Rails will try to use Mongrel if it's installed when started with <tt>rails server</tt>, otherwise
40
+ Rails will use WEBrick, the webserver that ships with Ruby. But you can also use Rails
40
41
  with a variety of other web servers.
41
42
 
42
43
  Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
@@ -164,20 +165,20 @@ Finally, when you're ready to resume execution, you enter "cont"
164
165
 
165
166
  == Console
166
167
 
167
- You can interact with the domain model by starting the console through <tt>script/console</tt>.
168
+ You can interact with the domain model by starting the console through <tt>rails console</tt>.
168
169
  Here you'll have all parts of the application configured, just like it is when the
169
170
  application is running. You can inspect domain models, change values, and save to the
170
171
  database. Starting the script without arguments will launch it in the development environment.
171
- Passing an argument will specify a different environment, like <tt>script/console production</tt>.
172
+ Passing an argument will specify a different environment, like <tt>rails console production</tt>.
172
173
 
173
174
  To reload your controllers and models after launching the console run <tt>reload!</tt>
174
175
 
175
176
  == dbconsole
176
177
 
177
- You can go to the command line of your database directly through <tt>script/dbconsole</tt>.
178
+ You can go to the command line of your database directly through <tt>rails dbconsole</tt>.
178
179
  You would be connected to the database with the credentials defined in database.yml.
179
180
  Starting the script without arguments will connect you to the development database. Passing an
180
- argument will connect you to a different database, like <tt>script/dbconsole production</tt>.
181
+ argument will connect you to a different database, like <tt>rails dbconsole production</tt>.
181
182
  Currently works for mysql, postgresql and sqlite.
182
183
 
183
184
  == Description of Contents
@@ -207,7 +208,7 @@ app/views/layouts
207
208
 
208
209
  app/helpers
209
210
  Holds view helpers that should be named like weblogs_helper.rb. These are generated
210
- for you automatically when using script/generate for controllers. Helpers can be used to
211
+ for you automatically when using rails generate for controllers. Helpers can be used to
211
212
  wrap functionality for your views into methods.
212
213
 
213
214
  config
@@ -234,7 +235,7 @@ script
234
235
  Helper scripts for automation and generation.
235
236
 
236
237
  test
237
- Unit and functional tests along with fixtures. When using the script/generate scripts, template
238
+ Unit and functional tests along with fixtures. When using the rails generate command, template
238
239
  test files will be generated for you and placed in this directory.
239
240
 
240
241
  vendor