diff options
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/application.rb | 6 | ||||
-rw-r--r-- | railties/lib/rails/generators.rb | 38 | ||||
-rw-r--r-- | railties/lib/rails/railtie.rb | 15 |
3 files changed, 44 insertions, 15 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 4d05f8115c..b92a7ff129 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -8,7 +8,7 @@ module Rails class << self attr_writer :config alias configure class_eval - delegate :initialize!, :load_tasks, :root, :to => :instance + delegate :initialize!, :load_tasks, :load_generators, :root, :to => :instance private :new def instance @@ -82,6 +82,10 @@ module Rails end end + def load_generators + plugins.each { |p| p.load_generators } + end + def initializers initializers = Bootstrap.new(self).initializers plugins.each { |p| initializers += p.initializers } diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 736c36c0dc..d3175e6a9d 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -168,7 +168,7 @@ module Rails # Show help message with available generators. def self.help - traverse_load_paths! + lookup! namespaces = subclasses.map{ |k| k.namespace } namespaces.sort! @@ -226,22 +226,10 @@ module Rails nil end - # This will try to load any generator in the load path to show in help. - def self.traverse_load_paths! #:nodoc: - $LOAD_PATH.each do |base| - Dir[File.join(base, "{generators,rails_generators}", "**", "*_generator.rb")].each do |path| - begin - require path - rescue Exception => e - # No problem - end - end - end - end - # Receives namespaces in an array and tries to find matching generators # in the load path. def self.lookup(namespaces) #:nodoc: + load_generators_from_railties! paths = namespaces_to_paths(namespaces) paths.each do |path| @@ -261,6 +249,28 @@ module Rails end end + # This will try to load any generator in the load path to show in help. + def self.lookup! #:nodoc: + load_generators_from_railties! + + $LOAD_PATH.each do |base| + Dir[File.join(base, "{generators,rails_generators}", "**", "*_generator.rb")].each do |path| + begin + require path + rescue Exception => e + # No problem + end + end + end + end + + # Allow generators to be loaded from custom paths. + def self.load_generators_from_railties! #:nodoc: + return if defined?(@generators_from_railties) || Rails.application.nil? + @generators_from_railties = true + Rails.application.load_generators + end + # Convert namespaces to paths by replacing ":" for "/" and adding # an extra lookup. For example, "rails:model" should be searched # in both: "rails/model/model_generator" and "rails/model_generator". diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index 43a0303c5b..e3297148e5 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -35,13 +35,28 @@ module Rails @rake_tasks end + def self.generators(&blk) + @generators ||= [] + @generators << blk if blk + @generators + end + def rake_tasks self.class.rake_tasks end + def generators + self.class.generators + end + def load_tasks return unless rake_tasks rake_tasks.each { |blk| blk.call } end + + def load_generators + return unless generators + generators.each { |blk| blk.call } + end end end |