TextMate Ruby代码段发布

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TextMate Ruby代码段发布相关的知识,希望对你有一定的参考价值。

  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

以上是关于TextMate Ruby代码段发布的主要内容,如果未能解决你的问题,请参考以下文章

HTML HTML5 TextMate代码段

TextMate代码段

@字体面TextMate代码段

控制台.log()-Textmate代码段

边框半径TextMate代码段

Ruby 在 n *milli* 秒后超时一段代码