Permalink
Browse files

Generators load path now will be Ruby load path. If you want to use r…

…spec:install generator, you need generators/rspec/install_generator in your load path.
  • Loading branch information...
1 parent e75ea47 commit 9fffdc5cdb80b1824473a6d7ae1fedf9e74aa748 @josevalim josevalim committed Jan 18, 2010
Showing with 77 additions and 95 deletions.
  1. +8 −0 {railties/lib/rails → activerecord/lib}/generators/active_record.rb
  2. +1 −1 {railties/lib/rails → activerecord/lib}/generators/active_record/migration/migration_generator.rb
  3. 0 {railties/lib/rails → activerecord/lib}/generators/active_record/migration/templates/migration.rb
  4. +1 −1 {railties/lib/rails → activerecord/lib}/generators/active_record/model/model_generator.rb
  5. 0 {railties/lib/rails → activerecord/lib}/generators/active_record/model/templates/migration.rb
  6. 0 {railties/lib/rails → activerecord/lib}/generators/active_record/model/templates/model.rb
  7. +1 −1 {railties/lib/rails → activerecord/lib}/generators/active_record/observer/observer_generator.rb
  8. 0 {railties/lib/rails → activerecord/lib}/generators/active_record/observer/templates/observer.rb
  9. +1 −1 ...ils → activerecord/lib}/generators/active_record/session_migration/session_migration_generator.rb
  10. 0 ...s/lib/rails → activerecord/lib}/generators/active_record/session_migration/templates/migration.rb
  11. 0 railties/lib/{rails → }/generators/erb.rb
  12. +1 −1 railties/lib/{rails → }/generators/erb/controller/controller_generator.rb
  13. 0 railties/lib/{rails → }/generators/erb/controller/templates/view.html.erb
  14. +1 −1 railties/lib/{rails → }/generators/erb/mailer/mailer_generator.rb
  15. 0 railties/lib/{rails → }/generators/erb/mailer/templates/view.erb
  16. +1 −1 railties/lib/{rails → }/generators/erb/scaffold/scaffold_generator.rb
  17. 0 railties/lib/{rails → }/generators/erb/scaffold/templates/_form.html.erb
  18. 0 railties/lib/{rails → }/generators/erb/scaffold/templates/edit.html.erb
  19. 0 railties/lib/{rails → }/generators/erb/scaffold/templates/index.html.erb
  20. 0 railties/lib/{rails → }/generators/erb/scaffold/templates/layout.html.erb
  21. 0 railties/lib/{rails → }/generators/erb/scaffold/templates/new.html.erb
  22. 0 railties/lib/{rails → }/generators/erb/scaffold/templates/show.html.erb
  23. 0 railties/lib/{rails → }/generators/rails/app/USAGE
  24. +2 −2 railties/lib/{rails → }/generators/rails/app/app_generator.rb
  25. 0 railties/lib/{rails → }/generators/rails/app/templates/Gemfile
  26. 0 railties/lib/{rails → }/generators/rails/app/templates/README
  27. 0 railties/lib/{rails → }/generators/rails/app/templates/Rakefile
  28. 0 railties/lib/{rails → }/generators/rails/app/templates/app/controllers/application_controller.rb
  29. 0 railties/lib/{rails → }/generators/rails/app/templates/app/helpers/application_helper.rb
  30. 0 ...rails/generator/templates/templates → generators/rails/app/templates/app/models}/.empty_directory
  31. 0 ...ails/app/templates/test/unit → generators/rails/app/templates/app/views/layouts}/.empty_directory
  32. 0 railties/lib/{rails → }/generators/rails/app/templates/config.ru
  33. 0 railties/lib/{rails → }/generators/rails/app/templates/config/application.rb
  34. 0 railties/lib/{rails → }/generators/rails/app/templates/config/boot.rb
  35. 0 railties/lib/{rails → }/generators/rails/app/templates/config/databases/frontbase.yml
  36. 0 railties/lib/{rails → }/generators/rails/app/templates/config/databases/ibm_db.yml
  37. 0 railties/lib/{rails → }/generators/rails/app/templates/config/databases/mysql.yml
  38. 0 railties/lib/{rails → }/generators/rails/app/templates/config/databases/oracle.yml
  39. 0 railties/lib/{rails → }/generators/rails/app/templates/config/databases/postgresql.yml
  40. 0 railties/lib/{rails → }/generators/rails/app/templates/config/databases/sqlite3.yml
  41. 0 railties/lib/{rails → }/generators/rails/app/templates/config/environment.rb
  42. 0 railties/lib/{rails → }/generators/rails/app/templates/config/environments/development.rb.tt
  43. 0 railties/lib/{rails → }/generators/rails/app/templates/config/environments/production.rb.tt
  44. 0 railties/lib/{rails → }/generators/rails/app/templates/config/environments/test.rb.tt
  45. 0 railties/lib/{rails → }/generators/rails/app/templates/config/initializers/backtrace_silencers.rb
  46. 0 ...ib/{rails → }/generators/rails/app/templates/config/initializers/cookie_verification_secret.rb.tt
  47. 0 railties/lib/{rails → }/generators/rails/app/templates/config/initializers/inflections.rb
  48. 0 railties/lib/{rails → }/generators/rails/app/templates/config/initializers/mime_types.rb
  49. 0 railties/lib/{rails → }/generators/rails/app/templates/config/initializers/session_store.rb.tt
  50. 0 railties/lib/{rails → }/generators/rails/app/templates/config/locales/en.yml
  51. 0 railties/lib/{rails → }/generators/rails/app/templates/config/routes.rb
  52. 0 railties/lib/{rails → }/generators/rails/app/templates/db/seeds.rb
  53. 0 railties/lib/{rails → }/generators/rails/app/templates/doc/README_FOR_APP
  54. 0 railties/lib/{rails → }/generators/rails/app/templates/gitignore
  55. 0 railties/lib/{rails → }/generators/rails/app/templates/public/404.html
  56. 0 railties/lib/{rails → }/generators/rails/app/templates/public/422.html
  57. 0 railties/lib/{rails → }/generators/rails/app/templates/public/500.html
  58. 0 railties/lib/{rails → }/generators/rails/app/templates/public/favicon.ico
  59. BIN railties/lib/{rails → }/generators/rails/app/templates/public/images/rails.png
  60. 0 railties/lib/{rails → }/generators/rails/app/templates/public/index.html
  61. 0 railties/lib/{rails → }/generators/rails/app/templates/public/javascripts/application.js
  62. 0 railties/lib/{rails → }/generators/rails/app/templates/public/javascripts/controls.js
  63. 0 railties/lib/{rails → }/generators/rails/app/templates/public/javascripts/dragdrop.js
  64. 0 railties/lib/{rails → }/generators/rails/app/templates/public/javascripts/effects.js
  65. 0 railties/lib/{rails → }/generators/rails/app/templates/public/javascripts/prototype.js
  66. 0 railties/lib/{rails → }/generators/rails/app/templates/public/robots.txt
  67. 0 .../templates/test/integration → generators/rails/app/templates/public/stylesheets}/.empty_directory
  68. 0 railties/lib/{rails → }/generators/rails/app/templates/script/about
  69. 0 railties/lib/{rails → }/generators/rails/app/templates/script/console.tt
  70. 0 railties/lib/{rails → }/generators/rails/app/templates/script/dbconsole.tt
  71. 0 railties/lib/{rails → }/generators/rails/app/templates/script/destroy
  72. 0 railties/lib/{rails → }/generators/rails/app/templates/script/generate
  73. 0 railties/lib/{rails → }/generators/rails/app/templates/script/performance/benchmarker
  74. 0 railties/lib/{rails → }/generators/rails/app/templates/script/performance/profiler
  75. 0 railties/lib/{rails → }/generators/rails/app/templates/script/plugin
  76. 0 railties/lib/{rails → }/generators/rails/app/templates/script/runner
  77. 0 railties/lib/{rails → }/generators/rails/app/templates/script/server.tt
  78. 0 ...ls/app/templates/test/functional → generators/rails/app/templates/test/fixtures}/.empty_directory
  79. 0 ...ls/app/templates/test/fixtures → generators/rails/app/templates/test/functional}/.empty_directory
  80. 0 .../templates/public/stylesheets → generators/rails/app/templates/test/integration}/.empty_directory
  81. 0 railties/lib/{rails → }/generators/rails/app/templates/test/performance/browsing_test.rb
  82. 0 railties/lib/{rails → }/generators/rails/app/templates/test/test_helper.rb
  83. 0 ...ails/app/templates/app/views/layouts → generators/rails/app/templates/test/unit}/.empty_directory
  84. 0 railties/lib/{rails → }/generators/rails/controller/USAGE
  85. 0 railties/lib/{rails → }/generators/rails/controller/controller_generator.rb
  86. 0 railties/lib/{rails → }/generators/rails/controller/templates/controller.rb
  87. 0 railties/lib/{rails → }/generators/rails/generator/USAGE
  88. 0 railties/lib/{rails → }/generators/rails/generator/generator_generator.rb
  89. 0 railties/lib/{rails → }/generators/rails/generator/templates/%file_name%_generator.rb.tt
  90. 0 railties/lib/{rails → }/generators/rails/generator/templates/USAGE.tt
  91. 0 ...rails/app/templates/app/models → generators/rails/generator/templates/templates}/.empty_directory
  92. 0 railties/lib/{rails → }/generators/rails/helper/USAGE
  93. 0 railties/lib/{rails → }/generators/rails/helper/helper_generator.rb
  94. 0 railties/lib/{rails → }/generators/rails/helper/templates/helper.rb
  95. 0 railties/lib/{rails → }/generators/rails/integration_test/USAGE
  96. 0 railties/lib/{rails → }/generators/rails/integration_test/integration_test_generator.rb
  97. 0 railties/lib/{rails → }/generators/rails/mailer/USAGE
  98. 0 railties/lib/{rails → }/generators/rails/mailer/mailer_generator.rb
  99. 0 railties/lib/{rails → }/generators/rails/mailer/templates/mailer.rb
  100. 0 railties/lib/{rails → }/generators/rails/metal/USAGE
  101. 0 railties/lib/{rails → }/generators/rails/metal/metal_generator.rb
  102. 0 railties/lib/{rails → }/generators/rails/metal/templates/metal.rb
  103. 0 railties/lib/{rails → }/generators/rails/migration/USAGE
  104. 0 railties/lib/{rails → }/generators/rails/migration/migration_generator.rb
  105. 0 railties/lib/{rails → }/generators/rails/model/USAGE
  106. 0 railties/lib/{rails → }/generators/rails/model/model_generator.rb
  107. +1 −0 railties/lib/{rails → }/generators/rails/model_subclass/model_subclass_generator.rb
  108. 0 railties/lib/{rails → }/generators/rails/observer/USAGE
  109. 0 railties/lib/{rails → }/generators/rails/observer/observer_generator.rb
  110. 0 railties/lib/{rails → }/generators/rails/performance_test/USAGE
  111. 0 railties/lib/{rails → }/generators/rails/performance_test/performance_test_generator.rb
  112. 0 railties/lib/{rails → }/generators/rails/plugin/USAGE
  113. +1 −1 railties/lib/{rails → }/generators/rails/plugin/plugin_generator.rb
  114. 0 railties/lib/{rails → }/generators/rails/plugin/templates/MIT-LICENSE.tt
  115. 0 railties/lib/{rails → }/generators/rails/plugin/templates/README.tt
  116. 0 railties/lib/{rails → }/generators/rails/plugin/templates/Rakefile.tt
  117. 0 railties/lib/{rails → }/generators/rails/plugin/templates/init.rb
  118. 0 railties/lib/{rails → }/generators/rails/plugin/templates/install.rb
  119. 0 railties/lib/{rails → }/generators/rails/plugin/templates/lib/%file_name%.rb.tt
  120. 0 railties/lib/{rails → }/generators/rails/plugin/templates/tasks/%file_name%_tasks.rake.tt
  121. 0 railties/lib/{rails → }/generators/rails/plugin/templates/uninstall.rb
  122. 0 railties/lib/{rails → }/generators/rails/resource/USAGE
  123. +1 −1 railties/lib/{rails → }/generators/rails/resource/resource_generator.rb
  124. 0 railties/lib/{rails → }/generators/rails/scaffold/USAGE
  125. +1 −1 railties/lib/{rails → }/generators/rails/scaffold/scaffold_generator.rb
  126. 0 railties/lib/{rails → }/generators/rails/scaffold_controller/USAGE
  127. 0 railties/lib/{rails → }/generators/rails/scaffold_controller/scaffold_controller_generator.rb
  128. 0 railties/lib/{rails → }/generators/rails/scaffold_controller/templates/controller.rb
  129. 0 railties/lib/{rails → }/generators/rails/session_migration/USAGE
  130. 0 railties/lib/{rails → }/generators/rails/session_migration/session_migration_generator.rb
  131. 0 railties/lib/{rails → }/generators/rails/stylesheets/USAGE
  132. 0 railties/lib/{rails → }/generators/rails/stylesheets/stylesheets_generator.rb
  133. 0 railties/lib/{rails → }/generators/rails/stylesheets/templates/scaffold.css
  134. 0 railties/lib/{rails → }/generators/test_unit.rb
  135. +1 −1 railties/lib/{rails → }/generators/test_unit/controller/controller_generator.rb
  136. 0 railties/lib/{rails → }/generators/test_unit/controller/templates/functional_test.rb
  137. +1 −1 railties/lib/{rails → }/generators/test_unit/helper/helper_generator.rb
  138. 0 railties/lib/{rails → }/generators/test_unit/helper/templates/helper_test.rb
  139. +1 −1 railties/lib/{rails → }/generators/test_unit/integration/integration_generator.rb
  140. 0 railties/lib/{rails → }/generators/test_unit/integration/templates/integration_test.rb
  141. +1 −1 railties/lib/{rails → }/generators/test_unit/mailer/mailer_generator.rb
  142. 0 railties/lib/{rails → }/generators/test_unit/mailer/templates/fixture
  143. 0 railties/lib/{rails → }/generators/test_unit/mailer/templates/unit_test.rb
  144. +1 −1 railties/lib/{rails → }/generators/test_unit/model/model_generator.rb
  145. 0 railties/lib/{rails → }/generators/test_unit/model/templates/fixtures.yml
  146. 0 railties/lib/{rails → }/generators/test_unit/model/templates/unit_test.rb
  147. +1 −1 railties/lib/{rails → }/generators/test_unit/observer/observer_generator.rb
  148. 0 railties/lib/{rails → }/generators/test_unit/observer/templates/unit_test.rb
  149. +1 −1 railties/lib/{rails → }/generators/test_unit/performance/performance_generator.rb
  150. 0 railties/lib/{rails → }/generators/test_unit/performance/templates/performance_test.rb
  151. +1 −1 railties/lib/{rails → }/generators/test_unit/plugin/plugin_generator.rb
  152. 0 railties/lib/{rails → }/generators/test_unit/plugin/templates/%file_name%_test.rb.tt
  153. 0 railties/lib/{rails → }/generators/test_unit/plugin/templates/test_helper.rb
  154. +1 −1 railties/lib/{rails → }/generators/test_unit/scaffold/scaffold_generator.rb
  155. 0 railties/lib/{rails → }/generators/test_unit/scaffold/templates/functional_test.rb
  156. +26 −52 railties/lib/rails/generators.rb
  157. +1 −1 railties/lib/rails/generators/base.rb
  158. +2 −2 railties/test/generators/actions_test.rb
  159. +1 −1 railties/test/generators/app_generator_test.rb
  160. +1 −1 railties/test/generators/controller_generator_test.rb
  161. +1 −1 railties/test/generators/generator_generator_test.rb
  162. +0 −1 railties/test/generators/generators_test_helper.rb
  163. +1 −1 railties/test/generators/helper_generator_test.rb
  164. +1 −1 railties/test/generators/integration_test_generator_test.rb
  165. +1 −1 railties/test/generators/mailer_generator_test.rb
  166. +1 −1 railties/test/generators/metal_generator_test.rb
  167. +1 −1 railties/test/generators/migration_generator_test.rb
  168. +1 −1 railties/test/generators/model_generator_test.rb
  169. +1 −1 railties/test/generators/named_base_test.rb
  170. +1 −1 railties/test/generators/observer_generator_test.rb
  171. +1 −1 railties/test/generators/performance_test_generator_test.rb
  172. +1 −1 railties/test/generators/plugin_generator_test.rb
  173. +1 −1 railties/test/generators/resource_generator_test.rb
  174. +1 −1 railties/test/generators/scaffold_controller_generator_test.rb
  175. +1 −1 railties/test/generators/scaffold_generator_test.rb
  176. +1 −1 railties/test/generators/session_migration_generator_test.rb
  177. +1 −1 railties/test/generators/stylesheets_generator_test.rb
@@ -8,6 +8,14 @@ module Generators
class Base < Rails::Generators::NamedBase #:nodoc:
include Rails::Generators::Migration
+ def self.source_root
+ @_ar_source_root ||= begin
+ if base_name && generator_name
+ File.expand_path(File.join(base_name, generator_name, 'templates'), File.dirname(__FILE__))
+ end
+ end
+ end
+
protected
# Implement the required interface for Rails::Generators::Migration.
#
@@ -1,4 +1,4 @@
-require 'rails/generators/active_record'
+require 'generators/active_record'
module ActiveRecord
module Generators
@@ -1,4 +1,4 @@
-require 'rails/generators/active_record'
+require 'generators/active_record'
module ActiveRecord
module Generators
@@ -1,4 +1,4 @@
-require 'rails/generators/active_record'
+require 'generators/active_record'
module ActiveRecord
module Generators
@@ -1,4 +1,4 @@
-require 'rails/generators/active_record'
+require 'generators/active_record'
module ActiveRecord
module Generators
@@ -1,4 +1,4 @@
-require 'rails/generators/erb'
+require 'generators/erb'
module Erb
module Generators
@@ -1,4 +1,4 @@
-require 'rails/generators/erb'
+require 'generators/erb'
module Erb
module Generators
@@ -1,4 +1,4 @@
-require 'rails/generators/erb'
+require 'generators/erb'
require 'rails/generators/resource_helpers'
module Erb
@@ -5,7 +5,7 @@
module Rails::Generators
# We need to store the RAILS_DEV_PATH in a constant, otherwise the path
# can change in Ruby 1.8.7 when we FileUtils.cd.
- RAILS_DEV_PATH = File.expand_path("../../../../../..", File.dirname(__FILE__))
+ RAILS_DEV_PATH = File.expand_path("../../../../..", File.dirname(__FILE__))
class AppGenerator < Base
DATABASES = %w( mysql oracle postgresql sqlite3 frontbase ibm_db )
@@ -35,7 +35,7 @@ class AppGenerator < Base
:desc => "Skip Prototype files"
class_option :skip_git, :type => :boolean, :aliases => "-G", :default => false,
- :desc => "Skip Git ignores and keeps"
+ :desc => "Skip Git ignores and keeps"
# Add bin/rails options
class_option :version, :type => :boolean, :aliases => "-v", :group => :rails,
@@ -1,5 +1,6 @@
module Rails
module Generators
+ # TODO Deprecate me in a release > Rails 3.0
class ModelSubclassGenerator < Base
desc "model_subclass is deprecated. Invoke model with --parent option instead."
@@ -1,4 +1,4 @@
-require 'rails/generators/rails/generator/generator_generator'
+require 'generators/rails/generator/generator_generator'
module Rails
module Generators
@@ -1,5 +1,5 @@
-require 'rails/generators/rails/model/model_generator'
require 'rails/generators/resource_helpers'
+require 'generators/rails/model/model_generator'
module Rails
module Generators
@@ -1,4 +1,4 @@
-require 'rails/generators/rails/resource/resource_generator'
+require 'generators/rails/resource/resource_generator'
module Rails
module Generators
@@ -1,4 +1,4 @@
-require 'rails/generators/test_unit'
+require 'generators/test_unit'
module TestUnit
module Generators
@@ -1,4 +1,4 @@
-require 'rails/generators/test_unit'
+require 'generators/test_unit'
module TestUnit
module Generators
@@ -1,4 +1,4 @@
-require 'rails/generators/test_unit'
+require 'generators/test_unit'
module TestUnit
module Generators
@@ -1,4 +1,4 @@
-require 'rails/generators/test_unit'
+require 'generators/test_unit'
module TestUnit
module Generators
@@ -1,4 +1,4 @@
-require 'rails/generators/test_unit'
+require 'generators/test_unit'
module TestUnit
module Generators
@@ -1,4 +1,4 @@
-require 'rails/generators/test_unit'
+require 'generators/test_unit'
module TestUnit
module Generators
@@ -1,4 +1,4 @@
-require 'rails/generators/test_unit'
+require 'generators/test_unit'
module TestUnit
module Generators
@@ -1,4 +1,4 @@
-require 'rails/generators/test_unit'
+require 'generators/test_unit'
module TestUnit
module Generators
@@ -1,4 +1,4 @@
-require 'rails/generators/test_unit'
+require 'generators/test_unit'
require 'rails/generators/resource_helpers'
module TestUnit
@@ -87,18 +87,6 @@ def self.options #:nodoc:
@options ||= DEFAULT_OPTIONS.dup
end
- def self.gems_generators_paths #:nodoc:
- return [] unless defined?(Gem) && Gem.respond_to?(:loaded_specs)
- Gem.loaded_specs.inject([]) do |paths, (name, spec)|
- paths += Dir[File.join(spec.full_gem_path, "lib/{generators,rails_generators}")]
- end
- end
-
- def self.plugins_generators_paths #:nodoc:
- return [] unless defined?(Rails.root) && Rails.root
- Dir[File.join(Rails.root, "vendor", "plugins", "*", "lib", "{generators,rails_generators}")]
- end
-
# Hold configured generators fallbacks. If a plugin developer wants a
# generator group to fallback to another group in case of missing generators,
# they can add a fallback.
@@ -126,31 +114,6 @@ def self.subclasses
@subclasses ||= []
end
- # Generators load paths used on lookup. The lookup happens as:
- #
- # 1) lib generators
- # 2) vendor/plugin generators
- # 3) vendor/gems generators
- # 4) ~/rails/generators
- # 5) rubygems generators
- # 6) builtin generators
- #
- # TODO Remove hardcoded paths for all, except (6).
- #
- def self.load_paths
- @load_paths ||= begin
- paths = []
- paths += Dir[File.join(Rails.root, "lib", "{generators,rails_generators}")] if defined?(Rails.root) && Rails.root
- paths += Dir[File.join(Thor::Util.user_home, ".rails", "{generators,rails_generators}")]
- paths += self.plugins_generators_paths
- paths += self.gems_generators_paths
- paths << File.expand_path(File.join(File.dirname(__FILE__), "generators"))
- paths.uniq!
- paths
- end
- end
- load_paths # Cache load paths. Needed to avoid __FILE__ pointing to wrong paths.
-
# Rails finds namespaces similar to thor, it only adds one rule:
#
# Generators names must end with "_generator.rb". This is required because Rails
@@ -170,6 +133,12 @@ def self.load_paths
def self.find_by_namespace(name, base=nil, context=nil) #:nodoc:
base = "rails" unless base || context || name.to_s.include?(?:)
+ lookups = []
+ lookups << "#{base}:#{name}" if base
+ lookups << "#{name}:#{context}" if context
+ lookups << "#{name}"
+ lookups << "rails:#{name}" unless base || context || name.to_s.include?(?:)
+
# Mount regexps to lookup
regexps = []
regexps << /^#{base}:[\w:]*#{name}$/ if base
@@ -183,7 +152,7 @@ def self.find_by_namespace(name, base=nil, context=nil) #:nodoc:
return klass if klass
# Try to require other generators by looking in load_paths
- lookup(name, context)
+ lookup(lookups)
unchecked = subclasses - checked
klass = find_by_regexps(regexps, unchecked)
return klass if klass
@@ -255,22 +224,27 @@ def self.invoke_fallbacks_for(name, base) #:nodoc:
# Receives namespaces in an array and tries to find matching generators
# in the load path.
- def self.lookup(*attempts) #:nodoc:
+ def self.lookup(attempts) #:nodoc:
attempts.compact!
attempts.uniq!
- attempts = "{#{attempts.join(',')}}_generator.rb"
-
- self.load_paths.each do |path|
- Dir[File.join(path, '**', attempts)].each do |file|
- begin
- require file
- rescue NameError => e
- raise unless e.message =~ /Rails::Generator/
- warn "[WARNING] Could not load generator at #{file.inspect} because it's a Rails 2.x generator, which is not supported anymore"
- rescue Exception => e
- warn "[WARNING] Could not load generator at #{file.inspect}. Error: #{e.message}"
- end
- end
+
+ attempts.each do |attempt|
+ last = attempt.split(':').last
+
+ # TODO Support rails_generators
+ require_generator "generators/#{attempt.gsub(':', '/')}/#{last}_generator"
+ require_generator "generators/#{attempt.gsub(':', '/')}_generator"
+ end
+ end
+
+ def self.require_generator(path)
+ begin
+ require path
+ rescue LoadError => e
+ raise unless e.message =~ /#{Regexp.escape(path)}$/
+ rescue NameError => e
+ raise unless e.message =~ /Rails::Generator/
+ warn "[WARNING] Could not load generator at #{path.inspect} because it's a Rails 2.x generator, which is not supported anymore. Error: #{e.message}"
end
end
@@ -17,7 +17,7 @@ class Base < Thor::Group
def self.source_root
@_rails_source_root ||= begin
if base_name && generator_name
- File.expand_path(File.join(File.dirname(__FILE__), base_name, generator_name, 'templates'))
+ File.expand_path(File.join("../../generators", base_name, generator_name, 'templates'), File.dirname(__FILE__))
end
end
end
@@ -1,8 +1,8 @@
require 'generators/generators_test_helper'
-require 'rails/generators/rails/app/app_generator'
+require 'generators/rails/app/app_generator'
# TODO This line shouldn't be required
-require 'rails/generators/rails/model/model_generator'
+require 'generators/rails/model/model_generator'
class ActionsTest < GeneratorsTestCase
tests Rails::Generators::AppGenerator
@@ -1,6 +1,6 @@
require 'abstract_unit'
require 'generators/generators_test_helper'
-require 'rails/generators/rails/app/app_generator'
+require 'generators/rails/app/app_generator'
class AppGeneratorTest < GeneratorsTestCase
arguments [destination_root]
@@ -1,5 +1,5 @@
require 'generators/generators_test_helper'
-require 'rails/generators/rails/controller/controller_generator'
+require 'generators/rails/controller/controller_generator'
class ControllerGeneratorTest < GeneratorsTestCase
arguments %w(Account foo bar)
@@ -1,5 +1,5 @@
require 'generators/generators_test_helper'
-require 'rails/generators/rails/generator/generator_generator'
+require 'generators/rails/generator/generator_generator'
class GeneratorGeneratorTest < GeneratorsTestCase
arguments %w(awesome)
@@ -10,7 +10,6 @@ def self.root
require 'rails/generators'
require 'rails/generators/test_case'
-require 'rubygems'
require 'active_record'
require 'action_dispatch'
@@ -1,5 +1,5 @@
require 'generators/generators_test_helper'
-require 'rails/generators/rails/helper/helper_generator'
+require 'generators/rails/helper/helper_generator'
ObjectHelper = Class.new
AnotherObjectHelperTest = Class.new
@@ -1,5 +1,5 @@
require 'generators/generators_test_helper'
-require 'rails/generators/rails/integration_test/integration_test_generator'
+require 'generators/rails/integration_test/integration_test_generator'
class IntegrationTestGeneratorTest < GeneratorsTestCase
arguments %w(integration)
@@ -1,5 +1,5 @@
require 'generators/generators_test_helper'
-require 'rails/generators/rails/mailer/mailer_generator'
+require 'generators/rails/mailer/mailer_generator'
class MailerGeneratorTest < GeneratorsTestCase
arguments %w(notifier foo bar)
@@ -1,5 +1,5 @@
require 'generators/generators_test_helper'
-require 'rails/generators/rails/metal/metal_generator'
+require 'generators/rails/metal/metal_generator'
class MetalGeneratorTest < GeneratorsTestCase
arguments %w(foo)
@@ -1,5 +1,5 @@
require 'generators/generators_test_helper'
-require 'rails/generators/rails/migration/migration_generator'
+require 'generators/rails/migration/migration_generator'
class MigrationGeneratorTest < GeneratorsTestCase
def test_migration
@@ -1,5 +1,5 @@
require 'generators/generators_test_helper'
-require 'rails/generators/rails/model/model_generator'
+require 'generators/rails/model/model_generator'
class ModelGeneratorTest < GeneratorsTestCase
arguments %w(Account name:string age:integer)
@@ -1,5 +1,5 @@
require 'generators/generators_test_helper'
-require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator'
+require 'generators/rails/scaffold_controller/scaffold_controller_generator'
# Mock out what we need from AR::Base.
module ActiveRecord
@@ -1,5 +1,5 @@
require 'generators/generators_test_helper'
-require 'rails/generators/rails/observer/observer_generator'
+require 'generators/rails/observer/observer_generator'
class ObserverGeneratorTest < GeneratorsTestCase
arguments %w(account)
@@ -1,5 +1,5 @@
require 'generators/generators_test_helper'
-require 'rails/generators/rails/performance_test/performance_test_generator'
+require 'generators/rails/performance_test/performance_test_generator'
class PerformanceTestGeneratorTest < GeneratorsTestCase
arguments %w(performance)
@@ -1,5 +1,5 @@
require 'generators/generators_test_helper'
-require 'rails/generators/rails/plugin/plugin_generator'
+require 'generators/rails/plugin/plugin_generator'
class PluginGeneratorTest < GeneratorsTestCase
arguments %w(plugin_fu)
@@ -1,5 +1,5 @@
require 'generators/generators_test_helper'
-require 'rails/generators/rails/resource/resource_generator'
+require 'generators/rails/resource/resource_generator'
class ResourceGeneratorTest < GeneratorsTestCase
arguments %w(account)
Oops, something went wrong.

2 comments on commit 9fffdc5

@jnicklas
Contributor

This is an awesome change, good to reuse an existing system. Does this mean that generators in lib/generators/my_library in gems are pulled in automatically?

@josevalim
Member

Yes, if you follow the conventions, for example:
If you have "lib/generators/awesome_generator.rb" with AwesomeGenerator defined, it can be invoked as script/generate awesome.
If you have "lib/generators/my_library/awesome_generator.rb" with MyLibrary::AwesomeGenerator, it can be invoked as script/generator my_library:awesome.

Please sign in to comment.