From ed048a52fb452fb10069df74ed3c4b210facba56 Mon Sep 17 00:00:00 2001 From: James Herdman Date: Mon, 20 Apr 2009 21:31:56 -0400 Subject: [PATCH] Fix template commands for Windows --- .../generators/applications/app/template_runner.rb | 21 +++++++++++++------ 1 files changed, 14 insertions(+), 7 deletions(-) diff --git a/railties/lib/rails_generator/generators/applications/app/template_runner.rb b/railties/lib/rails_generator/generators/applications/app/template_runner.rb index 3b49b1f..8bd7488 100644 --- a/railties/lib/rails_generator/generators/applications/app/template_runner.rb +++ b/railties/lib/rails_generator/generators/applications/app/template_runner.rb @@ -78,7 +78,7 @@ module Rails run_ruby_script("script/plugin install #{options[:svn] || options[:git]}", false) end else - log "! no git or svn provided for #{name}. skipping..." + log "! no git or svn provided for #{name}. skipping..." end end @@ -247,8 +247,7 @@ module Rails # Executes a ruby script (taking into account WIN32 platform quirks) def run_ruby_script(command, log_action = true) - ruby_command = RUBY_PLATFORM=~ /win32/ ? 'ruby ' : '' - run("#{ruby_command}#{command}", log_action) + run [app("ruby"), command].join(" "), log_action end # Runs the supplied rake task @@ -262,8 +261,8 @@ module Rails def rake(command, options = {}) log 'rake', command env = options[:env] || 'development' - sudo = options[:sudo] ? 'sudo ' : '' - in_root { run("#{sudo}rake #{command} RAILS_ENV=#{env}", false) } + sudo = options[:sudo] ? 'sudo' : '' + in_root { run [sudo, app('rake'), "RAILS_ENV=#{env}"].join(" "), false } end # Just run the capify command in root @@ -274,7 +273,7 @@ module Rails # def capify! log 'capifying' - in_root { run('capify .', false) } + in_root { run("#{app('capify')} .", false) } end # Add Rails to /vendor/rails @@ -285,7 +284,7 @@ module Rails # def freeze!(args = {}) log 'vendor', 'rails edge' - in_root { run('rake rails:freeze:edge', false) } + in_root { rake("rails:freeze:edge", false) } end # Make an entry in Rails routing file conifg/routes.rb @@ -307,6 +306,14 @@ module Rails protected + # Often times Windows has a *.bat file to in place of an executable. When + # you say 'ruby', it thinks 'ruby.bat'. This method wraps up common logic + # behind translating application names like 'ruby' and 'rake' to 'ruby.bat' + # and 'rake.bat'. + def app(name) + RUBY_PLATFORM =~ /win32/ ? "#{name}.bat" : name + end + # Get a user's input # # ==== Example -- 1.6.2.3