diff options
author | Stefan Sprenger <stefan.sprenger@dkd.de> | 2011-05-26 17:59:00 +0200 |
---|---|---|
committer | Stefan Sprenger <stefan.sprenger@dkd.de> | 2011-05-26 17:59:00 +0200 |
commit | 835c9cee3ede273030bae5dcf465176d64b287dd (patch) | |
tree | 208c4290d695e22349a1d299ec1a09c2d2bf52d8 /railties | |
parent | 60281af200180d752b8300bdad3c0a869d56347f (diff) | |
download | rails-835c9cee3ede273030bae5dcf465176d64b287dd.tar.gz rails-835c9cee3ede273030bae5dcf465176d64b287dd.tar.bz2 rails-835c9cee3ede273030bae5dcf465176d64b287dd.zip |
Introducing engine commands
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/commands/generate.rb | 7 | ||||
-rw-r--r-- | railties/lib/rails/engine/commands.rb | 37 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt | 7 |
3 files changed, 48 insertions, 3 deletions
diff --git a/railties/lib/rails/commands/generate.rb b/railties/lib/rails/commands/generate.rb index b6f9a003d1..1f742f8853 100644 --- a/railties/lib/rails/commands/generate.rb +++ b/railties/lib/rails/commands/generate.rb @@ -7,4 +7,9 @@ if ARGV.first.in?([nil, "-h", "--help"]) end name = ARGV.shift -Rails::Generators.invoke name, ARGV, :behavior => :invoke, :destination_root => Rails.root + +if defined?(ENGINE_ROOT) + Rails::Generators.invoke name, ARGV, :behavior => :invoke, :destination_root => ENGINE_ROOT +else + Rails::Generators.invoke name, ARGV, :behavior => :invoke, :destination_root => Rails.root +end diff --git a/railties/lib/rails/engine/commands.rb b/railties/lib/rails/engine/commands.rb new file mode 100644 index 0000000000..33a7cd5805 --- /dev/null +++ b/railties/lib/rails/engine/commands.rb @@ -0,0 +1,37 @@ +require 'active_support/core_ext/object/inclusion' + +ARGV << '--help' if ARGV.empty? + +aliases = { + "g" => "generate" +} + +command = ARGV.shift +command = aliases[command] || command + +case command +when 'generate' + require 'rails/generators' + + require ENGINE_PATH + engine = ::Rails::Engine.find(ENGINE_ROOT) + engine.load_generators + + require 'rails/commands/generate' + +when '--version', '-v' + ARGV.unshift '--version' + require 'rails/commands/application' + +else + puts "Error: Command not recognized" unless command.in?(['-h', '--help']) + puts <<-EOT +Usage: rails COMMAND [ARGS] + +The common rails commands available for engines are: + generate Generate new code (short-cut alias: "g") + +All commands can be run with -h for more information. + EOT + exit(1) +end diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt b/railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt index 65d82abf6d..0d7becad4f 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt +++ b/railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt @@ -1,4 +1,7 @@ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. -ENGINE_PATH = File.expand_path('../..', __FILE__) -load File.expand_path('../../<%= dummy_path %>/script/rails', __FILE__) +ENGINE_ROOT = File.expand_path('../..', __FILE__) +ENGINE_PATH = File.expand_path('../../lib/<%= name -%>/engine', __FILE__) + +require 'rails/all' +require 'rails/engine/commands' |