从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).
#!/usr/bin/env ruby -w require "xmlrpc/client" require "cgi" require ENV['TM_SUPPORT_PATH'] + "/lib/exit_codes.rb" require ENV['TM_SUPPORT_PATH'] + "/lib/escape.rb" COCOA_DIALOG = ENV['TM_SUPPORT_PATH'] + '/bin/CocoaDialog' API_KEY = "YOUR_API_KEY_HERE" if 0 == server.call("user.checkkey", API_KEY) puts "#{API_KEY} was not accepted as a valid API Key" TextMate.exit_show_tool_tip end begin result = server.call("snippet.list", API_KEY) result_list = "" result.each { |row| result_list += "'#{row['id']} : #{row['title']}' " } res=%x("#{COCOA_DIALOG}" dropdown --title "Retrieve Snippet" --string-output --text "You have #{result.length} Snipplr entries stored under this API Key." --items #{result_list} --button1 'Retreive' --button2 'Cancel') button, item = res.split case button when 'Retreive' $snippet = server.call("snippet.get", item) when 'Cancel' puts "Snippet retreival cancelled." TextMate.exit_show_tool_tip end rescue XMLRPC::FaultException => err if err.faultString =~ /No snippets found/ print "You don't have any snippets yet!" else print "Error: " + err.faultCode.to_s + ", " + err.faultString end TextMate.exit_show_tool_tip rescue print "Error: #{$!}" TextMate.exit_show_tool_tip end
以上是关于从Snipplr获取一个代码片段的主要内容,如果未能解决你的问题,请参考以下文章