Index: Manifest.txt =================================================================== --- Manifest.txt (revision 237) +++ Manifest.txt (working copy) @@ -1,7 +1,8 @@ ./bin/sake +./lib/help.rb +./lib/pastie.rb ./lib/sake.rb ./lib/server.rb -./lib/help.rb ./Manifest.txt ./Rakefile ./README Index: lib/sake.rb =================================================================== --- lib/sake.rb (revision 237) +++ lib/sake.rb (working copy) @@ -14,6 +14,7 @@ die "# Sake requires the ruby2ruby gem and Ruby 1.8.6." end require File.dirname(__FILE__) + '/help' +require File.dirname(__FILE__) + '/pastie' ## # Show all Sake tasks (but no local Rake tasks), optionally only those matching a pattern. @@ -38,6 +39,10 @@ # Uninstall an installed task. # $ sake -u db:remigrate # +# Stores the source of a task into a pastie (http://pastie.caboo.se) +# Returns the url of the pastie to stdout +# $ sake -p routes +# # Can be passed one or more tasks. # # Invoke a Sake task. @@ -68,7 +73,7 @@ module Version Major = '1' Minor = '0' - Tweak = '3' + Tweak = '5' String = [ Major, Minor, Tweak ].join('.') end @@ -123,9 +128,17 @@ # $ sake -e routes # $ sake -e Rakefile db:remigrate elsif index = @args.index('-e') - return examine(index) + die examine(index) ## + # Examine a Rake task and save to pastie (http://pastie.caboos.se) and return url of pastie + # $ sake -p routes + # $ sake -p Rakefile db:remigrate + elsif index = @args.index('-p') + print Pastie.paste(examine(index)) + exit + + ## # Start a Mongrel handler which will serve local Rake tasks # to anyone who wants them. # @@ -213,20 +226,20 @@ # They didn't pass any args in, so just show the ~/.sake file unless task - die Store.tasks.to_ruby + return Store.tasks.to_ruby end # Try to find the task we think they asked for. tasks = file ? TasksFile.parse(file).tasks : Store.tasks if tasks[task] - die tasks[task].to_ruby + return tasks[task].to_ruby end # Didn't find the task. See if it's a file and, if so, spit # it out. unless (tasks = TasksFile.parse(task).tasks).empty? - die tasks.to_ruby + return tasks.to_ruby end # Failure. On all counts. Index: lib/pastie.rb =================================================================== --- lib/pastie.rb (revision 0) +++ lib/pastie.rb (revision 0) @@ -0,0 +1,34 @@ +require 'rubygems' +require 'active_support' +class Pastie + PASTE_URL = ENV['SAKE_PASTIE_URL'] || ENV['PASTIE_URL'] || + 'http://pastie.caboo.se/pastes/create' + + require 'fileutils' + + def self.paste(text) + text_file = Tempfile.open('w+') + text_file << text + text_file.flush + + cmd = <<-EOS + curl #{PASTE_URL} \ + -s -L -o /dev/null -w "%{url_effective}" \ + -H "Expect:" \ + -F "paste[parser]=ruby" \ + -F "paste[restricted]=0" \ + -F "paste[authorization]=burger" \ + -F "paste[body]=<#{text_file.path}" \ + -F "key=" \ + -F "x=27" \ + -F "y=27" + EOS + + out = %x{ + #{cmd} + } + + text_file.close(true) + out + end +end