diff options
Diffstat (limited to 'railties/lib/rails')
-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' |