aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/generators/base.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2009-07-15 22:37:22 +0200
committerJosé Valim <jose.valim@gmail.com>2009-07-15 22:37:22 +0200
commit8d47078a492de9e3fca61ec6894e975d570ef449 (patch)
tree447d845fdcbbf5ae337568fa1b1c7eb37f87de00 /railties/lib/generators/base.rb
parentb4ef958de6b16294094de28d00ba25fe2f48accc (diff)
downloadrails-8d47078a492de9e3fca61ec6894e975d570ef449.tar.gz
rails-8d47078a492de9e3fca61ec6894e975d570ef449.tar.bz2
rails-8d47078a492de9e3fca61ec6894e975d570ef449.zip
Added source_paths to rails generators. If a template is added to RAILS_ROOT/lib/templates/base/generator it will be used. For example, to customize edit.html.erb template on scaffold, just add a customized copy at RAILS_ROOT/lib/templates/erb/scaffold.
Diffstat (limited to 'railties/lib/generators/base.rb')
-rw-r--r--railties/lib/generators/base.rb22
1 files changed, 18 insertions, 4 deletions
diff --git a/railties/lib/generators/base.rb b/railties/lib/generators/base.rb
index 0ef6d061ff..4c38e0f5be 100644
--- a/railties/lib/generators/base.rb
+++ b/railties/lib/generators/base.rb
@@ -6,15 +6,16 @@ module Rails
end
class Base < Thor::Group
+ include Thor::Actions
+ include Rails::Generators::Actions
+
# Automatically sets the source root based on the class name.
#
def self.source_root
- File.expand_path(File.join(File.dirname(__FILE__), base_name, generator_name, 'templates'))
+ @_rails_source_root ||= File.expand_path(File.join(File.dirname(__FILE__),
+ base_name, generator_name, 'templates'))
end
- include Thor::Actions
- include Rails::Generators::Actions
-
# Tries to get the description from a USAGE file one folder above the source
# root otherwise uses a default description.
#
@@ -148,6 +149,19 @@ module Rails
super(name, options)
end
+ # Cache source root and add lib/generators/base/generator/templates to
+ # source paths.
+ #
+ def self.inherited(base) #:nodoc:
+ super
+ base.source_root # Cache source root
+
+ if defined?(RAILS_ROOT) && base.name !~ /Base$/
+ path = File.expand_path(File.join(RAILS_ROOT, 'lib', 'templates'))
+ base.source_paths << File.join(path, base.base_name, base.generator_name)
+ end
+ end
+
protected
# Check whether the given class names are already taken by user