From af97ef71ff015527fc85270adac2552b5abfaea2 Mon Sep 17 00:00:00 2001 From: rubymood Date: Sat, 7 Mar 2009 21:30:31 +0100 Subject: [PATCH] Template runner enhancement: run_ruby_script merged into run method. Now use: run "ruby_script.rb", :ruby_script=>true :show_response option to check command response or when interaction is needed run "compass --rails -f blueprint .", :show_reponse=>true :puts option for automatized tasks run "compass --rails -f blueprint .", :puts=>["y","n"] --- .../generators/applications/app/template_runner.rb | 39 +++++++++++++------- 1 files changed, 26 insertions(+), 13 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 efed030..bf7708d 100644 --- a/railties/lib/rails_generator/generators/applications/app/template_runner.rb +++ b/railties/lib/rails_generator/generators/applications/app/template_runner.rb @@ -75,7 +75,7 @@ module Rails end elsif options[:git] || options[:svn] in_root do - run_ruby_script("script/plugin install #{options[:svn] || options[:git]}", false) + run("script/plugin install #{options[:svn] || options[:git]}", {:ruby_script => true}, false) end else log "! no git or svn provided for #{name}. skipping..." @@ -229,7 +229,7 @@ module Rails log 'generating', what argument = args.map(&:to_s).flatten.join(" ") - in_root { run_ruby_script("script/generate #{what} #{argument}", false) } + in_root { run("script/generate #{what} #{argument}", {:ruby_script => true}, false) } end # Executes a command @@ -237,18 +237,31 @@ module Rails # ==== Example # # inside('vendor') do - # run('ln -s ~/edge rails) + # run('ln -s ~/edge rails') # end # - def run(command, log_action = true) + # if yes?("Do you wanna manually config compass?") + # run "compass --rails -f #{ask("Wich framework want to use?")} .", :show_response=>true + # else + # run "compass --rails -f blueprint .", :puts=>["y","n"] #automatic configuration + # end + # + # run "ruby_script.rb", :ruby_script => true + def run(command, options = {}, log_action = true) + command = RUBY_PLATFORM=~ /win32/ ? 'ruby ' + command : command if options[:ruby_script] + log 'executing', "#{command} from #{Dir.pwd}" if log_action - `#{command}` - end - # 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) + if options.empty? + `#{command}` + elsif options[:show_response] + system command + elsif options[:puts] + require 'open3' + Open3.popen3 command do |stdin, stdout, stderr| + Array(options[:puts]).each { |opt| stdin.puts opt } + end + end end # Runs the supplied rake task @@ -263,7 +276,7 @@ module Rails log 'rake', command env = options[:env] || 'development' sudo = options[:sudo] ? 'sudo ' : '' - in_root { run("#{sudo}rake #{command} RAILS_ENV=#{env}", false) } + in_root { run("#{sudo}rake #{command} RAILS_ENV=#{env}", {}, false) } end # Just run the capify command in root @@ -274,7 +287,7 @@ module Rails # def capify! log 'capifying' - in_root { run('capify .', false) } + in_root { run('capify .', {}, false) } end # Add Rails to /vendor/rails @@ -285,7 +298,7 @@ module Rails # def freeze!(args = {}) log 'vendor', 'rails edge' - in_root { run('rake rails:freeze:edge', false) } + in_root { run('rake rails:freeze:edge', {}, false) } end # Make an entry in Rails routing file conifg/routes.rb -- 1.6.1.3 From 26b4e7b331699763558d9cbc669015515df57582 Mon Sep 17 00:00:00 2001 From: rubymood Date: Sat, 7 Mar 2009 21:30:31 +0100 Subject: [PATCH] Template runner enhancement: run_ruby_script merged into run method. Now use: run "ruby_script.rb", :ruby_script=>true :show_response option to check command response or when interaction is needed run "compass --rails -f blueprint .", :show_reponse=>true :puts option for automatized tasks run "compass --rails -f blueprint .", :puts=>["y","n"] modified: railties/lib/rails_generator/generators/applications/app/template_runner.rb --- .../generators/applications/app/template_runner.rb | 39 +++++++++++++------- 1 files changed, 26 insertions(+), 13 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 efed030..45901c4 100644 --- a/railties/lib/rails_generator/generators/applications/app/template_runner.rb +++ b/railties/lib/rails_generator/generators/applications/app/template_runner.rb @@ -75,7 +75,7 @@ module Rails end elsif options[:git] || options[:svn] in_root do - run_ruby_script("script/plugin install #{options[:svn] || options[:git]}", false) + run("script/plugin install #{options[:svn] || options[:git]}", {:ruby_script => true}, false) end else log "! no git or svn provided for #{name}. skipping..." @@ -229,7 +229,7 @@ module Rails log 'generating', what argument = args.map(&:to_s).flatten.join(" ") - in_root { run_ruby_script("script/generate #{what} #{argument}", false) } + in_root { run("script/generate #{what} #{argument}", {:ruby_script => true}, false) } end # Executes a command @@ -237,18 +237,31 @@ module Rails # ==== Example # # inside('vendor') do - # run('ln -s ~/edge rails) + # run('ln -s ~/edge rails') # end # - def run(command, log_action = true) + # if yes?("Do you wanna manually config compass?") + # run "compass --rails -f #{ask("Wich framework want to use?")} .", :show_response=>true + # else + # run "compass --rails -f blueprint .", :puts=>["y","n"] #automatic configuration + # end + # + # run "ruby_script.rb", :ruby_script => true + def run(command, options = {}, log_action = true) + command = RUBY_PLATFORM=~ /win32/ ? 'ruby ' + command : command if options.delete(:ruby_script) + log 'executing', "#{command} from #{Dir.pwd}" if log_action - `#{command}` - end - # 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) + if options.empty? + `#{command}` + elsif options[:show_response] + system command + elsif options[:puts] + require 'open3' + Open3.popen3 command do |stdin, stdout, stderr| + Array(options[:puts]).each { |opt| stdin.puts opt } + end + end end # Runs the supplied rake task @@ -263,7 +276,7 @@ module Rails log 'rake', command env = options[:env] || 'development' sudo = options[:sudo] ? 'sudo ' : '' - in_root { run("#{sudo}rake #{command} RAILS_ENV=#{env}", false) } + in_root { run("#{sudo}rake #{command} RAILS_ENV=#{env}", {}, false) } end # Just run the capify command in root @@ -274,7 +287,7 @@ module Rails # def capify! log 'capifying' - in_root { run('capify .', false) } + in_root { run('capify .', {}, false) } end # Add Rails to /vendor/rails @@ -285,7 +298,7 @@ module Rails # def freeze!(args = {}) log 'vendor', 'rails edge' - in_root { run('rake rails:freeze:edge', false) } + in_root { run('rake rails:freeze:edge', {}, false) } end # Make an entry in Rails routing file conifg/routes.rb -- 1.6.1.3