将代码段发布到Snipplr

Posted

tags:

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

Alternative bundle command for e (http://www.e-texteditor.com) or TextMate.

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

Changed the command to allow selection of language. (Thanks, Tyler!) Also it was unnecessary to escape entities when posting to Snipplr, so that caused problems. Please let me know if you have any issues with or suggestions for this command. If you're using TextMate, you'll need to alter the path to CocoaDialog, and you might as well use an environment variable for the API Key.

2/2/2007: Fixed a bug that prevented posting snippets with no tags. Languages are now sorted alphabetically.
  1. #!/usr/bin/env ruby -w
  2. require "xmlrpc/client"
  3. require ENV['TM_SUPPORT_PATH'] + "/lib/exit_codes.rb"
  4.  
  5. code = STDIN.read
  6. COCOA_DIALOG = ENV['TM_SUPPORT_PATH'] + '/bin/CocoaDialog.exe'
  7. API_KEY = "YOUR_API_KEY_HERE"
  8. server = XMLRPC::Client.new( "snipplr.com", "/xml-rpc.php")
  9.  
  10. if 0 == server.call("user.checkkey", API_KEY)
  11. puts "#{API_KEY} was not accepted as a valid API Key"
  12. TextMate.exit_show_tool_tip
  13. end
  14.  
  15. title_bx = %x("#{COCOA_DIALOG}" standard-inputbox
  16. --title "Snippet Name"
  17. --no-newline
  18. --informative text "Enter a name for your new snippet:" )
  19. button, title = title_bx.split(" ")
  20. TextMate.exit_discard if "2" == button || title.nil?
  21. languages = server.call("languages.list")
  22. langs_arr = []
  23. languages.each_value{|k| langs_arr.push(k)}
  24. language_list = ""
  25. langs_arr.sort.each{ |k| language_list += "'#{k}' "}
  26.  
  27. lang_bx = %x("#{COCOA_DIALOG}" dropdown
  28. --string-output --no-newline
  29. --title "Snippet Language"
  30. --text "Please choose a language for you snippet:"
  31. --items #{language_list}
  32. --button1 "Accept" --button2 "Cancel")
  33. button, language_selection = lang_bx.split(" ")
  34. TextMate.exit_discard if "Cancel" == button
  35. language = languages.index(language_selection)
  36.  
  37. tags_bx = %x("#{COCOA_DIALOG}" standard-inputbox
  38. --no-newline
  39. --title "Snippet Tags"
  40. --informative text "Enter A space delimited list of keywords:" )
  41. button, tags = tags_bx.split(" ")
  42. TextMate.exit_discard if "2" == button
  43. tags = "" if tags.nil?
  44.  
  45. server.call("snippet.post", API_KEY, title, code, tags, language)
  46. puts "Added your snippet!"

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

用于Snipplr API的Snipplr代码段结构

从备份您的代码段snipplr.com网站

备份你自己的snipplr.com网站片段

为啥这段代码会泄露? (简单的代码片段)

Chrome-Devtools代码片段中的多个JS库

TextMate Ruby代码段发布