diff options
author | José Valim <jose.valim@gmail.com> | 2009-06-25 17:34:09 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-06-26 11:59:13 +0200 |
commit | 0f1c325f3cd8bfbedc0a6e4925122016288e2817 (patch) | |
tree | 0eaecf50e4e72ab4a71958385c15930e6555615d | |
parent | 915f108d6a47b9c29e11ebe0b140ef017eb015b0 (diff) | |
download | rails-0f1c325f3cd8bfbedc0a6e4925122016288e2817.tar.gz rails-0f1c325f3cd8bfbedc0a6e4925122016288e2817.tar.bz2 rails-0f1c325f3cd8bfbedc0a6e4925122016288e2817.zip |
Improving generators runner.
-rwxr-xr-x | railties/bin/gen | 30 | ||||
-rw-r--r-- | railties/lib/generators/erb/mailer/mailer_generator.rb | 2 | ||||
-rw-r--r-- | railties/lib/generators/rails/mailer/mailer_generator.rb | 2 | ||||
-rw-r--r-- | railties/lib/generators/test_unit/mailer/mailer_generator.rb | 2 |
4 files changed, 27 insertions, 9 deletions
diff --git a/railties/bin/gen b/railties/bin/gen index fab4866407..8dc6ba3cb0 100755 --- a/railties/bin/gen +++ b/railties/bin/gen @@ -7,22 +7,40 @@ if %w(--version -v).include? ARGV.first exit(0) end +require File.dirname(__FILE__) + '/../lib/generators' + if ARGV.size == 0 - puts "Please select a generator. Options: foo, bar" - return + rails = Rails::Generators.builtin.map do |group, name| + name if group == "rails" + end + rails.compact! + rails.sort! + + others = Rails::Generators.builtin.map do |group, name| + "#{group}:#{name}" unless rails.include?(name) + end.compact + others.sort! + + puts "Please select a generator." + puts "Builtin: #{rails.join(', ')}." + puts "Others: #{others.join(', ')}." + + exit elsif ARGV.size == 1 ARGV << "--help" end -require File.dirname(__FILE__) + '/../lib/generators' - Rails::Generators.builtin.each do |group, name| require "generators/#{group}/#{name}/#{name}_generator" end -name = ARGV.shift +name = ARGV.shift +middle = name.sub(':', ':generators:') if name.count(':') == 1 +full = "rails:generators:#{name}" if name.count(':') == 0 -if klass = Thor::Util.find_by_namespace("rails:generators:#{name}") +if full && klass = Thor::Util.find_by_namespace(full) + klass.start +elsif middle && klass = Thor::Util.find_by_namespace(middle) klass.start elsif klass = Thor::Util.find_by_namespace(name) klass.start diff --git a/railties/lib/generators/erb/mailer/mailer_generator.rb b/railties/lib/generators/erb/mailer/mailer_generator.rb index 286e6ae70a..73db3d2484 100644 --- a/railties/lib/generators/erb/mailer/mailer_generator.rb +++ b/railties/lib/generators/erb/mailer/mailer_generator.rb @@ -1,7 +1,7 @@ module Erb module Generators class MailerGenerator < Base - argument :actions, :type => :array, :default => [] + argument :actions, :type => :array, :default => [], :banner => "method method" def create_view_folder empty_directory File.join("app", "views", file_path) diff --git a/railties/lib/generators/rails/mailer/mailer_generator.rb b/railties/lib/generators/rails/mailer/mailer_generator.rb index 15140f2127..6e7e6e811e 100644 --- a/railties/lib/generators/rails/mailer/mailer_generator.rb +++ b/railties/lib/generators/rails/mailer/mailer_generator.rb @@ -1,7 +1,7 @@ module Rails module Generators class MailerGenerator < NamedBase - argument :actions, :type => :array, :default => [] + argument :actions, :type => :array, :default => [], :banner => "method method" def check_class_collision class_collisions class_name diff --git a/railties/lib/generators/test_unit/mailer/mailer_generator.rb b/railties/lib/generators/test_unit/mailer/mailer_generator.rb index 125371b173..84e3024427 100644 --- a/railties/lib/generators/test_unit/mailer/mailer_generator.rb +++ b/railties/lib/generators/test_unit/mailer/mailer_generator.rb @@ -1,7 +1,7 @@ module TestUnit module Generators class MailerGenerator < Base - argument :actions, :type => :array, :default => [] + argument :actions, :type => :array, :default => [], :banner => "method method" def create_test_files template "unit_test.rb", File.join('test', 'unit', class_path, "#{file_name}_test.rb") |