TextMate Ruby代码段检索

Posted

tags:

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

  1. #!/usr/bin/ruby
  2. $: << ENV['TM_SUPPORT_PATH'] + '/lib'
  3.  
  4. require "cgi"
  5. require "ui"
  6. require "xmlrpc/client"
  7.  
  8. unless ENV['SNIPPLR_KEY']
  9. TextMate::UI.alert(:critical, "Snipplr error", "Please first set your 'SNIPPLR_KEY' in Preferences > Advanced > Shell Variables.")
  10. exit
  11. end
  12.  
  13. TextMate::UI.request_string(:title => "Get Snippet from Snipplr",
  14. :prompt => "Enter tags to search for:",
  15. :button1 => "Search") do |tag|
  16.  
  17. begin
  18. server = XMLRPC::Client.new2("http://snipplr.com/xml-rpc.php")
  19. snippet_list = server.call('snippet.list', ENV['SNIPPLR_KEY'], tag)
  20. rescue
  21. # fall through
  22. end
  23.  
  24. unless snippet_list and snippet_list.length > 0
  25. TextMate::UI.alert(:warning, "Snipplr result", "No snippets for '#{tag}' found.")
  26. else
  27. items = {}
  28. snippet_list.each { |r| items[r['title']] = r['id'] }
  29.  
  30. TextMate::UI.request_item(:items => items.keys.sort,
  31. :title => "Snipplr result",
  32. :prompt => "Choose",
  33. :string => "Select which snippet to paste") do |item|
  34. begin
  35. snippet = server.call('snippet.get', items[item])
  36. puts CGI.unescapehtml(snippet['source'])
  37. rescue
  38. TextMate::UI.alert(:critical, "Snipplr error", "Could not retrieve '#{item}'.")
  39. end
  40. end
  41. end
  42. end

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

HTML HTML5 TextMate代码段

TextMate代码段

@字体面TextMate代码段

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

边框半径TextMate代码段

TextMate命令段-在窗口标题中显示文档路径