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
@@ -0,0 +1,84 @@
1
+ module Rails
2
+
3
+ # The Plugin class should be an object which provides the following methods:
4
+ #
5
+ # * +name+ - used during initialisation to order the plugin (based on name and
6
+ # the contents of <tt>config.plugins</tt>)
7
+ # * +valid?+ - returns true if this plugin can be loaded
8
+ # * +load_paths+ - each path within the returned array will be added to the $LOAD_PATH
9
+ # * +load+ - finally 'load' the plugin.
10
+ #
11
+ # These methods are expected by the Rails::Plugin::Locator and Rails::Plugin::Loader classes.
12
+ # The default implementation returns the <tt>lib</tt> directory as its </tt>load_paths</tt>,
13
+ # and evaluates <tt>init.rb</tt> when <tt>load</tt> is called.
14
+ class Plugin
15
+ include Comparable
16
+
17
+ attr_reader :directory, :name
18
+
19
+ def initialize(directory)
20
+ @directory = directory
21
+ @name = File.basename(@directory) rescue nil
22
+ @loaded = false
23
+ end
24
+
25
+ def valid?
26
+ File.directory?(directory) && (has_lib_directory? || has_init_file?)
27
+ end
28
+
29
+ # Returns a list of paths this plugin wishes to make available in $LOAD_PATH
30
+ def load_paths
31
+ report_nonexistant_or_empty_plugin! unless valid?
32
+ has_lib_directory? ? [lib_path] : []
33
+ end
34
+
35
+ # Evaluates a plugin's init.rb file
36
+ def load(initializer)
37
+ return if loaded?
38
+ report_nonexistant_or_empty_plugin! unless valid?
39
+ evaluate_init_rb(initializer)
40
+ @loaded = true
41
+ end
42
+
43
+ def loaded?
44
+ @loaded
45
+ end
46
+
47
+ def <=>(other_plugin)
48
+ name <=> other_plugin.name
49
+ end
50
+
51
+ private
52
+
53
+ def report_nonexistant_or_empty_plugin!
54
+ raise LoadError, "Can not find the plugin named: #{name}"
55
+ end
56
+
57
+ def lib_path
58
+ File.join(directory, 'lib')
59
+ end
60
+
61
+ def init_path
62
+ File.join(directory, 'init.rb')
63
+ end
64
+
65
+ def has_lib_directory?
66
+ File.directory?(lib_path)
67
+ end
68
+
69
+ def has_init_file?
70
+ File.file?(init_path)
71
+ end
72
+
73
+ def evaluate_init_rb(initializer)
74
+ if has_init_file?
75
+ silence_warnings do
76
+ # Allow plugins to reference the current configuration object
77
+ config = initializer.configuration
78
+
79
+ eval(IO.read(init_path), binding, init_path)
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,150 @@
1
+ require "rails/plugin"
2
+
3
+ module Rails
4
+ class Plugin
5
+ class Loader
6
+ attr_reader :initializer
7
+
8
+ # Creates a new Plugin::Loader instance, associated with the given
9
+ # Rails::Initializer. This default implementation automatically locates
10
+ # all plugins, and adds all plugin load paths, when it is created. The plugins
11
+ # are then fully loaded (init.rb is evaluated) when load_plugins is called.
12
+ #
13
+ # It is the loader's responsibility to ensure that only the plugins specified
14
+ # in the configuration are actually loaded, and that the order defined
15
+ # is respected.
16
+ def initialize(initializer)
17
+ @initializer = initializer
18
+ end
19
+
20
+ # Returns the plugins to be loaded, in the order they should be loaded.
21
+ def plugins
22
+ @plugins ||= all_plugins.select { |plugin| should_load?(plugin) }.sort { |p1, p2| order_plugins(p1, p2) }
23
+ end
24
+
25
+ # Returns all the plugins that could be found by the current locators.
26
+ def all_plugins
27
+ @all_plugins ||= locate_plugins
28
+ @all_plugins
29
+ end
30
+
31
+ def load_plugins
32
+ plugins.each do |plugin|
33
+ plugin.load(initializer)
34
+ register_plugin_as_loaded(plugin)
35
+ end
36
+ ensure_all_registered_plugins_are_loaded!
37
+ end
38
+
39
+ # Adds the load paths for every plugin into the $LOAD_PATH. Plugin load paths are
40
+ # added *after* the application's <tt>lib</tt> directory, to ensure that an application
41
+ # can always override code within a plugin.
42
+ #
43
+ # Plugin load paths are also added to Dependencies.load_paths, and Dependencies.load_once_paths.
44
+ def add_plugin_load_paths
45
+ plugins.each do |plugin|
46
+ plugin.load_paths.each do |path|
47
+ $LOAD_PATH.insert(application_lib_index + 1, path)
48
+ Dependencies.load_paths << path
49
+ Dependencies.load_once_paths << path
50
+ end
51
+ end
52
+ $LOAD_PATH.uniq!
53
+ end
54
+
55
+ protected
56
+
57
+ # The locate_plugins method uses each class in config.plugin_locators to
58
+ # find the set of all plugins available to this Rails application.
59
+ def locate_plugins
60
+ configuration.plugin_locators.map { |locator|
61
+ locator.new(initializer).plugins
62
+ }.flatten
63
+ # TODO: sorting based on config.plugins
64
+ end
65
+
66
+ def register_plugin_as_loaded(plugin)
67
+ initializer.loaded_plugins << plugin
68
+ end
69
+
70
+ def configuration
71
+ initializer.configuration
72
+ end
73
+
74
+ def should_load?(plugin)
75
+ # uses Plugin#name and Plugin#valid?
76
+ enabled?(plugin) && plugin.valid?
77
+ end
78
+
79
+ def order_plugins(plugin_a, plugin_b)
80
+ if !explicit_plugin_loading_order?
81
+ plugin_a <=> plugin_b
82
+ else
83
+ if !explicitly_enabled?(plugin_a) && !explicitly_enabled?(plugin_b)
84
+ plugin_a <=> plugin_b
85
+ else
86
+ effective_order_of(plugin_a) <=> effective_order_of(plugin_b)
87
+ end
88
+ end
89
+ end
90
+
91
+ def effective_order_of(plugin)
92
+ if explicitly_enabled?(plugin)
93
+ registered_plugin_names.index(plugin.name)
94
+ else
95
+ registered_plugin_names.index('all')
96
+ end
97
+ end
98
+
99
+ def application_lib_index
100
+ $LOAD_PATH.index(File.join(RAILS_ROOT, 'lib')) || 0
101
+ end
102
+
103
+ def enabled?(plugin)
104
+ !explicit_plugin_loading_order? || registered?(plugin)
105
+ end
106
+
107
+ def explicit_plugin_loading_order?
108
+ !registered_plugin_names.nil?
109
+ end
110
+
111
+ def registered?(plugin)
112
+ explicit_plugin_loading_order? && registered_plugins_names_plugin?(plugin)
113
+ end
114
+
115
+ def explicitly_enabled?(plugin)
116
+ !explicit_plugin_loading_order? || explicitly_registered?(plugin)
117
+ end
118
+
119
+ def explicitly_registered?(plugin)
120
+ explicit_plugin_loading_order? && registered_plugin_names.include?(plugin.name)
121
+ end
122
+
123
+ def registered_plugins_names_plugin?(plugin)
124
+ registered_plugin_names.include?(plugin.name) || registered_plugin_names.include?('all')
125
+ end
126
+
127
+ # The plugins that have been explicitly listed with config.plugins. If this list is nil
128
+ # then it means the client does not care which plugins or in what order they are loaded,
129
+ # so we load all in alphabetical order. If it is an empty array, we load no plugins, if it is
130
+ # non empty, we load the named plugins in the order specified.
131
+ def registered_plugin_names
132
+ configuration.plugins ? configuration.plugins.map(&:to_s) : nil
133
+ end
134
+
135
+ def loaded?(plugin_name)
136
+ initializer.loaded_plugins.detect { |plugin| plugin.name == plugin_name.to_s }
137
+ end
138
+
139
+ def ensure_all_registered_plugins_are_loaded!
140
+ if explicit_plugin_loading_order?
141
+ if configuration.plugins.detect {|plugin| plugin != :all && !loaded?(plugin) }
142
+ missing_plugins = configuration.plugins - (plugins + [:all])
143
+ raise LoadError, "Could not locate the following plugins: #{missing_plugins.to_sentence}"
144
+ end
145
+ end
146
+ end
147
+
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,78 @@
1
+ module Rails
2
+ class Plugin
3
+
4
+ # The Plugin::Locator class should be subclasses to provide custom plugin-finding
5
+ # abilities to Rails (i.e. loading plugins from Gems, etc). Each subclass should implement
6
+ # the <tt>located_plugins</tt> method, which return an array of Plugin objects that have been found.
7
+ class Locator
8
+ include Enumerable
9
+
10
+ attr_reader :initializer
11
+
12
+ def initialize(initializer)
13
+ @initializer = initializer
14
+ end
15
+
16
+ # This method should return all the plugins which this Plugin::Locator can find
17
+ # These will then be used by the current Plugin::Loader, which is responsible for actually
18
+ # loading the plugins themselves
19
+ def plugins
20
+ raise "The `plugins' method must be defined by concrete subclasses of #{self.class}"
21
+ end
22
+
23
+ def each(&block)
24
+ plugins.each(&block)
25
+ end
26
+
27
+ def plugin_names
28
+ plugins.map(&:name)
29
+ end
30
+ end
31
+
32
+ # The Rails::Plugin::FileSystemLocator will try to locate plugins by examining the directories
33
+ # the the paths given in configuration.plugin_paths. Any plugins that can be found are returned
34
+ # in a list.
35
+ #
36
+ # The criteria for a valid plugin in this case is found in Rails::Plugin#valid?, although
37
+ # other subclasses of Rails::Plugin::Locator can of course use different conditions.
38
+ class FileSystemLocator < Locator
39
+
40
+ # Returns all the plugins which can be loaded in the filesystem, under the paths given
41
+ # by configuration.plugin_paths.
42
+ def plugins
43
+ initializer.configuration.plugin_paths.flatten.inject([]) do |plugins, path|
44
+ plugins.concat locate_plugins_under(path)
45
+ plugins
46
+ end.flatten
47
+ end
48
+
49
+ private
50
+
51
+ # Attempts to create a plugin from the given path. If the created plugin is valid?
52
+ # (see Rails::Plugin#valid?) then the plugin instance is returned; otherwise nil.
53
+ def create_plugin(path)
54
+ plugin = Rails::Plugin.new(path)
55
+ plugin.valid? ? plugin : nil
56
+ end
57
+
58
+ # This starts at the base path looking for valid plugins (see Rails::Plugin#valid?).
59
+ # Since plugins can be nested arbitrarily deep within an unspecified number of intermediary
60
+ # directories, this method runs recursively until it finds a plugin directory, e.g.
61
+ #
62
+ # locate_plugins_under('vendor/plugins/acts/acts_as_chunky_bacon')
63
+ # => <Rails::Plugin name: 'acts_as_chunky_bacon' ... >
64
+ #
65
+ def locate_plugins_under(base_path)
66
+ Dir.glob(File.join(base_path, '*')).inject([]) do |plugins, path|
67
+ if plugin = create_plugin(path)
68
+ plugins << plugin
69
+ elsif File.directory?(path)
70
+ plugins.concat locate_plugins_under(path)
71
+ end
72
+ plugins
73
+ end
74
+ end
75
+
76
+ end
77
+ end
78
+ end
@@ -1,8 +1,8 @@
1
1
  module Rails
2
2
  module VERSION #:nodoc:
3
- MAJOR = 1
4
- MINOR = 2
5
- TINY = 6
3
+ MAJOR = 2
4
+ MINOR = 0
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -26,13 +26,14 @@ module Rails
26
26
  # +controller+ generator:
27
27
  #
28
28
  # generators/
29
- # controller/
30
- # controller_generator.rb
31
- # templates/
32
- # controller.rb
33
- # functional_test.rb
34
- # helper.rb
35
- # view.rhtml
29
+ # components/
30
+ # controller/
31
+ # controller_generator.rb
32
+ # templates/
33
+ # controller.rb
34
+ # functional_test.rb
35
+ # helper.rb
36
+ # view.html.erb
36
37
  #
37
38
  # The directory name (+controller+) matches the name of the generator file
38
39
  # (controller_generator.rb) and class (+ControllerGenerator+). The files
@@ -40,7 +41,7 @@ module Rails
40
41
  # directory.
41
42
  #
42
43
  # The filenames of the templates don't matter, but choose something that
43
- # will be self-explatatory since you will be referencing these in the
44
+ # will be self-explanatory since you will be referencing these in the
44
45
  # +manifest+ method inside your generator subclass.
45
46
  #
46
47
  #
@@ -228,7 +229,8 @@ module Rails
228
229
  @name = name
229
230
  base_name, @class_path, @file_path, @class_nesting, @class_nesting_depth = extract_modules(@name)
230
231
  @class_name_without_nesting, @singular_name, @plural_name = inflect_names(base_name)
231
- @table_name = ActiveRecord::Base.pluralize_table_names ? plural_name : singular_name
232
+ @table_name = (!defined?(ActiveRecord::Base) || ActiveRecord::Base.pluralize_table_names) ? plural_name : singular_name
233
+ @table_name.gsub! '/', '_'
232
234
  if @class_nesting.empty?
233
235
  @class_name = @class_name_without_nesting
234
236
  else
@@ -70,7 +70,7 @@ module Rails
70
70
  end
71
71
 
72
72
  def current_migration_number
73
- Dir.glob("#{@migration_directory}/[0-9]*.rb").inject(0) do |max, file_path|
73
+ Dir.glob("#{RAILS_ROOT}/#{@migration_directory}/[0-9]*_*.rb").inject(0) do |max, file_path|
74
74
  n = File.basename(file_path).split('_', 2).first.to_i
75
75
  if n > max then n else max end
76
76
  end
@@ -93,9 +93,9 @@ module Rails
93
93
  private
94
94
  # Ask the user interactively whether to force collision.
95
95
  def force_file_collision?(destination, src, dst, file_options = {}, &block)
96
- $stdout.print "overwrite #{destination}? [Ynaqd] "
97
- case $stdin.gets
98
- when /d/i
96
+ $stdout.print "overwrite #{destination}? (enter \"h\" for help) [Ynaqdh] "
97
+ case $stdin.gets.chomp
98
+ when /\Ad\z/i
99
99
  Tempfile.open(File.basename(destination), File.dirname(dst)) do |temp|
100
100
  temp.write render_file(src, file_options, &block)
101
101
  temp.rewind
@@ -103,14 +103,24 @@ module Rails
103
103
  end
104
104
  puts "retrying"
105
105
  raise 'retry diff'
106
- when /a/i
106
+ when /\Aa\z/i
107
107
  $stdout.puts "forcing #{spec.name}"
108
108
  options[:collision] = :force
109
- when /q/i
109
+ when /\Aq\z/i
110
110
  $stdout.puts "aborting #{spec.name}"
111
111
  raise SystemExit
112
- when /n/i then :skip
113
- else :force
112
+ when /\An\z/i then :skip
113
+ when /\Ay\z/i then :force
114
+ else
115
+ $stdout.puts <<-HELP
116
+ Y - yes, overwrite
117
+ n - no, do not overwrite
118
+ a - all, overwrite this and all others
119
+ q - quit, abort
120
+ d - diff, show the differences between the old and the new
121
+ h - help, show this help
122
+ HELP
123
+ raise 'retry'
114
124
  end
115
125
  rescue
116
126
  retry
@@ -260,7 +270,7 @@ module Rails
260
270
  end
261
271
 
262
272
  # Generate a file for a Rails application using an ERuby template.
263
- # Looks up and evalutes a template by name and writes the result.
273
+ # Looks up and evaluates a template by name and writes the result.
264
274
  #
265
275
  # The ERB template uses explicit trim mode to best control the
266
276
  # proliferation of whitespace in generated code. <%- trims leading
@@ -559,7 +569,7 @@ end_message
559
569
  return
560
570
  end
561
571
 
562
- logger.refreshing "#{template_options[:insert].gsub(/\.rhtml/,'')} inside #{relative_destination}"
572
+ logger.refreshing "#{template_options[:insert].gsub(/\.erb/,'')} inside #{relative_destination}"
563
573
 
564
574
  begin_mark = Regexp.quote(template_part_mark(template_options[:begin_mark], template_options[:mark_id]))
565
575
  end_mark = Regexp.quote(template_part_mark(template_options[:end_mark], template_options[:mark_id]))
@@ -7,10 +7,3 @@ Example:
7
7
 
8
8
  This generates a skeletal Rails installation in ~/Code/Ruby/weblog.
9
9
  See the README in the newly created application to get going.
10
-
11
- WARNING:
12
- Only specify --without-gems if you did not use gems to install Rails.
13
- Your application will expect to find activerecord, actionpack, and
14
- actionmailer directories in the vendor directory. A popular way to track
15
- the bleeding edge of Rails development is to checkout from source control
16
- directly to the vendor directory. See http://dev.rubyonrails.com
@@ -1,4 +1,6 @@
1
1
  require 'rbconfig'
2
+ require 'digest/md5'
3
+ require 'rails_generator/secret_key_generator'
2
4
 
3
5
  class AppGenerator < Rails::Generator::Base
4
6
  DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
@@ -6,7 +8,8 @@ class AppGenerator < Rails::Generator::Base
6
8
 
7
9
  DATABASES = %w(mysql oracle postgresql sqlite2 sqlite3 frontbase)
8
10
 
9
- default_options :db => "mysql", :shebang => DEFAULT_SHEBANG, :freeze => false
11
+ default_options :db => (ENV["RAILS_DEFAULT_DATABASE"] || "mysql"),
12
+ :shebang => DEFAULT_SHEBANG, :freeze => false
10
13
  mandatory_options :source => "#{File.dirname(__FILE__)}/../../../../.."
11
14
 
12
15
  def initialize(runtime_args, runtime_options = {})
@@ -22,6 +25,18 @@ class AppGenerator < Rails::Generator::Base
22
25
  script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
23
26
  dispatcher_options = { :chmod => 0755, :shebang => options[:shebang] }
24
27
 
28
+ # duplicate CGI::Session#generate_unique_id
29
+ md5 = Digest::MD5.new
30
+ now = Time.now
31
+ md5 << now.to_s
32
+ md5 << String(now.usec)
33
+ md5 << String(rand(0))
34
+ md5 << String($$)
35
+ md5 << @app_name
36
+
37
+ # Do our best to generate a secure secret key for CookieStore
38
+ secret = Rails::SecretKeyGenerator.new(@app_name).generate_secret
39
+
25
40
  record do |m|
26
41
  # Root directory and all subdirectories.
27
42
  m.directory ''
@@ -32,7 +47,7 @@ class AppGenerator < Rails::Generator::Base
32
47
  m.file "README", "README"
33
48
 
34
49
  # Application
35
- m.template "helpers/application.rb", "app/controllers/application.rb", :assigns => { :app_name => @app_name }
50
+ m.template "helpers/application.rb", "app/controllers/application.rb", :assigns => { :app_name => @app_name, :app_secret => md5.hexdigest }
36
51
  m.template "helpers/application_helper.rb", "app/helpers/application_helper.rb"
37
52
  m.template "helpers/test_helper.rb", "test/test_helper.rb"
38
53
 
@@ -44,15 +59,19 @@ class AppGenerator < Rails::Generator::Base
44
59
  m.template "configs/routes.rb", "config/routes.rb"
45
60
  m.template "configs/apache.conf", "public/.htaccess"
46
61
 
62
+ # Initializers
63
+ m.template "configs/initializers/inflections.rb", "config/initializers/inflections.rb"
64
+ m.template "configs/initializers/mime_types.rb", "config/initializers/mime_types.rb"
65
+
47
66
  # Environments
48
67
  m.file "environments/boot.rb", "config/boot.rb"
49
- m.template "environments/environment.rb", "config/environment.rb", :assigns => { :freeze => options[:freeze] }
68
+ m.template "environments/environment.rb", "config/environment.rb", :assigns => { :freeze => options[:freeze], :app_name => @app_name, :app_secret => secret }
50
69
  m.file "environments/production.rb", "config/environments/production.rb"
51
70
  m.file "environments/development.rb", "config/environments/development.rb"
52
71
  m.file "environments/test.rb", "config/environments/test.rb"
53
72
 
54
73
  # Scripts
55
- %w( about breakpointer console destroy generate performance/benchmarker performance/profiler process/reaper process/spawner process/inspector runner server plugin ).each do |file|
74
+ %w( about console destroy generate performance/benchmarker performance/profiler performance/request process/reaper process/spawner process/inspector runner server plugin ).each do |file|
56
75
  m.file "bin/#{file}", "script/#{file}", script_options
57
76
  end
58
77
 
@@ -62,7 +81,7 @@ class AppGenerator < Rails::Generator::Base
62
81
  m.file "dispatches/dispatch.fcgi", "public/dispatch.fcgi", dispatcher_options
63
82
 
64
83
  # HTML files
65
- %w(404 500 index).each do |file|
84
+ %w(404 422 500 index).each do |file|
66
85
  m.template "html/#{file}.html", "public/#{file}.html"
67
86
  end
68
87
 
@@ -121,7 +140,7 @@ class AppGenerator < Rails::Generator::Base
121
140
  app/models
122
141
  app/views/layouts
123
142
  config/environments
124
- components
143
+ config/initializers
125
144
  db
126
145
  doc
127
146
  lib