aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/generators.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2009-07-08 12:19:17 +0200
committerJosé Valim <jose.valim@gmail.com>2009-07-08 12:53:45 +0200
commitc9ea21717eefb9e9b49891c519cc4d121ef7bb74 (patch)
treea7901541789ab022074cf043fd764a4992455b7f /railties/lib/generators.rb
parent2699e9c2ddff13c5e19e1c95e838fa6d9a965c34 (diff)
downloadrails-c9ea21717eefb9e9b49891c519cc4d121ef7bb74.tar.gz
rails-c9ea21717eefb9e9b49891c519cc4d121ef7bb74.tar.bz2
rails-c9ea21717eefb9e9b49891c519cc4d121ef7bb74.zip
Generators are configured on initialization if RAILS_ENV=generators.
Diffstat (limited to 'railties/lib/generators.rb')
-rw-r--r--railties/lib/generators.rb91
1 files changed, 62 insertions, 29 deletions
diff --git a/railties/lib/generators.rb b/railties/lib/generators.rb
index dd61a686c2..a4ce92e04b 100644
--- a/railties/lib/generators.rb
+++ b/railties/lib/generators.rb
@@ -10,7 +10,6 @@ rescue LoadError
end
$:.unshift(File.dirname(__FILE__))
-require 'rails/version' unless defined?(Rails::VERSION)
# TODO Use vendored Thor
require 'rubygems'
@@ -22,6 +21,46 @@ require 'generators/named_base'
module Rails
module Generators
+ DEFAULT_ALIASES = {
+ :actions => '-a',
+ :fixture_replacement => '-r',
+ :orm => '-o',
+ :resource_controller => '-c',
+ :scaffold_controller => '-c',
+ :stylesheets => '-y',
+ :test_framework => '-t',
+ :template_engine => '-e'
+ }
+
+ DEFAULT_OPTIONS = {
+ :fixture => true,
+ :force_plural => false,
+ :helper => true,
+ :layout => true,
+ :migration => true,
+ :orm => 'active_record',
+ :resource_controller => 'controller',
+ :scaffold_controller => 'scaffold_controller',
+ :singleton => false,
+ :stylesheets => true,
+ :test_framework => 'test_unit',
+ :template_engine => 'erb',
+ :timestamps => true
+ }
+
+ def self.aliases
+ @@aliases ||= DEFAULT_ALIASES.dup
+ end
+
+ def self.options
+ @@options ||= DEFAULT_OPTIONS.dup
+ end
+
+ # Remove the color from output.
+ #
+ def self.no_color!
+ Thor::Base.shell = Thor::Shell::Basic
+ end
# Generators load paths used on lookup. The lookup happens as:
#
@@ -48,21 +87,7 @@ module Rails
paths
end
end
- load_path # Cache load paths
-
- # Keep builtin generators in an Array[Array[group, name]].
- #
- def self.builtin
- Dir[File.dirname(__FILE__) + '/generators/*/*'].collect do |file|
- file.split('/')[-2, 2]
- end
- end
-
- # Remove the color from output.
- #
- def self.no_color!
- Thor::Base.shell = Thor::Shell::Basic
- end
+ load_path # Cache load paths. Needed to avoid __FILE__ pointing to wrong paths.
# Receives a namespace and tries different combinations to find a generator.
#
@@ -106,6 +131,19 @@ module Rails
nil
end
+ # Receives a namespace, arguments and the behavior to invoke the generator.
+ # It's used as the default entry point for generate, destroy and update
+ # commands.
+ #
+ def self.invoke(namespace, args=ARGV, config={})
+ if klass = find_by_namespace(namespace, "rails")
+ args << "--help" if klass.arguments.any? { |a| a.required? } && args.empty?
+ klass.start args, config
+ else
+ puts "Could not find generator #{namespace}."
+ end
+ end
+
# Show help message with available generators.
#
def self.help
@@ -137,19 +175,6 @@ module Rails
puts "Others: #{others.join(', ')}." unless others.empty?
end
- # Receives a namespace, arguments and the behavior to invoke the generator.
- # It's used as the default entry point for generate, destroy and update
- # commands.
- #
- def self.invoke(namespace, args=ARGV, config={})
- if klass = find_by_namespace(namespace, "rails")
- args << "--help" if klass.arguments.any? { |a| a.required? } && args.empty?
- klass.start args, config
- else
- puts "Could not find generator #{namespace}."
- end
- end
-
protected
# Return all defined namespaces.
@@ -158,6 +183,14 @@ module Rails
Thor::Base.subclasses.map(&:namespace)
end
+ # Keep builtin generators in an Array[Array[group, name]].
+ #
+ def self.builtin
+ Dir[File.dirname(__FILE__) + '/generators/*/*'].collect do |file|
+ file.split('/')[-2, 2]
+ end
+ end
+
# Receives namespaces in an array and tries to find matching generators
# in the load path. Each path is traversed into directory lookups. For
# example: