从Snipplr获取一个代码片段

Posted

tags:

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

This command allows you to browse your snippet collection on Snipplr and retrieve them into e. Requires the installation of the wxCocoaDialog exe in the /Support/bin subdirectory.

Replace YOUR_API_KEY_HERE with the API key -- you can find it on your Settings page (http://snipplr.com/settings/).

Update 1/31/2007: I found escaping the $ was necessary to prevent the snippet engine from eating the variable.
Update 2/01/2007: Use the standard library function for escaping the snippet (instead of my own gsub() regex.
Update 2/02/2007: Add error checking code; handle empty accounts a bit more gracefully (and informatively).
  1. #!/usr/bin/env ruby -w
  2. require "xmlrpc/client"
  3. require "cgi"
  4. require ENV['TM_SUPPORT_PATH'] + "/lib/exit_codes.rb"
  5. require ENV['TM_SUPPORT_PATH'] + "/lib/escape.rb"
  6.  
  7. COCOA_DIALOG = ENV['TM_SUPPORT_PATH'] + '/bin/CocoaDialog'
  8. API_KEY = "YOUR_API_KEY_HERE"
  9. server = XMLRPC::Client.new( "snipplr.com", "/xml-rpc.php")
  10.  
  11. if 0 == server.call("user.checkkey", API_KEY)
  12. puts "#{API_KEY} was not accepted as a valid API Key"
  13. TextMate.exit_show_tool_tip
  14. end
  15.  
  16. begin
  17. result = server.call("snippet.list", API_KEY)
  18. result_list = ""
  19. result.each { |row| result_list += "'#{row['id']} : #{row['title']}' " }
  20.  
  21. res=%x("#{COCOA_DIALOG}" dropdown
  22. --title "Retrieve Snippet"
  23. --string-output
  24. --text "You have #{result.length} Snipplr entries stored under this API Key."
  25. --items #{result_list}
  26. --button1 'Retreive' --button2 'Cancel')
  27. button, item = res.split
  28. case button
  29. when 'Retreive'
  30. $snippet = server.call("snippet.get", item)
  31. when 'Cancel'
  32. puts "Snippet retreival cancelled."
  33. TextMate.exit_show_tool_tip
  34. end
  35. puts e_sn(CGI::unescapehtml($snippet['source']))
  36.  
  37. rescue XMLRPC::FaultException => err
  38. if err.faultString =~ /No snippets found/
  39. print "You don't have any snippets yet!"
  40. else
  41. print "Error: " + err.faultCode.to_s + ", " + err.faultString
  42. end
  43. TextMate.exit_show_tool_tip
  44. rescue
  45. print "Error: #{$!}"
  46. TextMate.exit_show_tool_tip
  47. end

以上是关于从Snipplr获取一个代码片段的主要内容,如果未能解决你的问题,请参考以下文章

常用python日期日志获取内容循环的代码片段

如何从Android片段中的相机获取图像

如何从 Firebase 获取数据到 Recyclerview 中的片段?

从底部工作表对话框片段中获取价值

从活动中获取片段内的按钮

如何从设置中获取数据并发送到此片段