Get from Pastie - Textmate Command


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #!/usr/bin/env ruby
  2.  
  3. ##Licence
  4. # ger_from_pastie.rb - A TextMate command for getting file from http://pastie.caboo.se
  5. #Copyright (C) 2006 Alessio Caiazza - abisso.org
  6. #
  7. #This program is free software; you can redistribute it and/or modify
  8. #it under the terms of the GNU General Public License as published by
  9. #the Free Software Foundation; either version 2 of the License
  10. #
  11. #This program is distributed in the hope that it will be useful,
  12. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. #GNU General Public License for more details.
  15. #
  16. #You should have received a copy of the GNU General Public License
  17. #along with this program; if not, write to the Free Software Foundation,
  18. #Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19.  
  20. ##Installation
  21. # for install create a new command in textmate and paste this code
  22. # select Input: None and Output: Create New Document
  23. # enjoy
  24.  
  25.  
  26. ##Script
  27. require 'net/http'
  28.  
  29. def request_document_number
  30. s = `\"#{ENV['TM_SUPPORT_PATH']}/bin/CocoaDialog.app/Contents/MacOS/CocoaDialog\" inputbox --title 'Get from Pastie' --informative-text 'Please enter the number of document to download' --text '' --button1 'Get' --button2 'Cancel'`
  31. case (a = s.split("\n"))[0].to_i
  32. when 1 then a[1].to_i
  33. when 2 then puts "Abort"; abort
  34. end
  35. end
  36.  
  37. begin
  38. number = request_document_number
  39. document = index = Net::HTTP.get_print(
  40. URI.parse("http://pastie.caboo.se/#{number}/download"))
  41. rescue
  42. "Some error, document number may be wrong"
  43. end

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.