Still copy application configuration to generator even if they are required earlier. Also tidy up the guide a little bit.

This commit is contained in:
José Valim 2010-06-02 08:45:03 +02:00
parent fdd203f964
commit afc1026986
5 changed files with 13 additions and 16 deletions

@ -322,16 +322,12 @@ config.generators do |g|
g.template_engine :erb
g.test_framework :shoulda, :fixture => false
g.stylesheets false
# Add a fallback!
g.fallbacks[:should] = :test_unit
end
</ruby>
And at the end of the same file:
<ruby>
require 'rails/generators'
Rails::Generators.fallbacks[:shoulda] = :test_unit
</ruby>
Now, if create a Comment scaffold, you will see that shoulda generators are being invoked, and at the end, they are just falling back to test unit generators:
<shell>
@ -361,7 +357,7 @@ $ rails generate scaffold Comment body:text
create test/unit/helpers/comments_helper_test.rb
</shell>
Such tool allows your generators to have single responsibility, increasing the code reuse and reducing the amount of code duplication.
Such tool allows your generators to have single responsibility, increasing the code reuse and reducing the amount of duplication.
h3. Changelog

@ -1,4 +1,5 @@
require 'rails/generators'
Rails::Generators.configure!
if [nil, "-h", "--help"].include?(ARGV.first)
Rails::Generators.help 'destroy'

@ -1,4 +1,5 @@
require 'rails/generators'
Rails::Generators.configure!
if [nil, "-h", "--help"].include?(ARGV.first)
Rails::Generators.help 'generate'

@ -68,6 +68,7 @@ def self.configure!(config = Rails.application.config.generators) #:nodoc:
options.deep_merge! config.options
fallbacks.merge! config.fallbacks
templates_path.concat config.templates
templates_path.uniq!
end
def self.templates_path
@ -328,10 +329,5 @@ def self.namespaces_to_paths(namespaces) #:nodoc:
paths.uniq!
paths
end
end
end
# If the application was already defined, configure generators,
# otherwise you have to configure it by hand.
Rails::Generators.configure! if Rails.respond_to?(:application) && Rails.application
end

@ -1,4 +1,6 @@
require 'abstract_unit'
require 'rails/generators'
require 'rails/generators/test_case'
module Rails
def self.root
@ -8,8 +10,9 @@ def self.root
Rails.application.config.root = Rails.root
Rails.application.config.generators.templates = [File.join(Rails.root, "lib", "templates")]
require 'rails/generators'
require 'rails/generators/test_case'
# Call configure to load the settings from
# Rails.application.config.generators to Rails::Generators
Rails::Generators.configure!
require 'active_record'
require 'action_dispatch'