TextMate Ruby Snippet Posting


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



Copy this code and paste it in your HTML
  1. #!/usr/bin/ruby
  2. $: << ENV['TM_SUPPORT_PATH'] + '/lib'
  3.  
  4. require "ui"
  5. require "xmlrpc/client"
  6.  
  7. unless ENV['SNIPPLR_KEY']
  8. puts "Please first set your 'SNIPPLR_KEY' in Preferences > Advanced > Shell Variables."
  9. exit
  10. end
  11.  
  12. unless ENV['TM_SELECTED_TEXT'] and ENV['TM_SELECTED_TEXT'].length > 0
  13. puts "No text selected."
  14. exit
  15. end
  16.  
  17. TextMate::UI.request_string(:title => "Post Snippet to Snipplr",
  18. :prompt => "Name this snippet:",
  19. :button1 => "Christen") do |title|
  20.  
  21. TextMate::UI.request_string(:title => "Post Snippet to Snipplr",
  22. :prompt => "Enter tags (space-delimited):",
  23. :button1 => "Post") do |tags|
  24.  
  25. begin
  26. server = XMLRPC::Client.new2("http://snipplr.com/xml-rpc.php")
  27. snippet_list = server.call( 'snippet.post',
  28. ENV['SNIPPLR_KEY'],
  29. title,
  30. ENV['TM_SELECTED_TEXT'],
  31. tags)
  32. puts "Snippet successfully posted."
  33. rescue
  34. TextMate::UI.alert(:critical, "Snipplr error", "Could not post snippet.")
  35. end
  36. end
  37. end

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.