Revision: 9516
Updated Code
at November 11, 2008 01:04 by nighthawk
Updated Code
#!/usr/bin/ruby $: << ENV['TM_SUPPORT_PATH'] + '/lib' require "cgi" require "ui" require "xmlrpc/client" unless ENV['SNIPPLR_KEY'] TextMate::UI.alert(:critical, "Snipplr error", "Please first set your 'SNIPPLR_KEY' in Preferences > Advanced > Shell Variables.") exit end TextMate::UI.request_string(:title => "Get Snippet from Snipplr", :prompt => "Enter tags to search for:", :button1 => "Search") do |tag| begin server = XMLRPC::Client.new2("http://snipplr.com/xml-rpc.php") snippet_list = server.call('snippet.list', ENV['SNIPPLR_KEY'], tag) rescue # fall through end unless snippet_list and snippet_list.length > 0 TextMate::UI.alert(:warning, "Snipplr result", "No snippets for '#{tag}' found.") else items = {} snippet_list.each { |r| items[r['title']] = r['id'] } TextMate::UI.request_item(:items => items.keys.sort, :title => "Snipplr result", :prompt => "Choose", :string => "Select which snippet to paste") do |item| begin snippet = server.call('snippet.get', items[item]) puts CGI.unescapeHTML(snippet['source']) rescue TextMate::UI.alert(:critical, "Snipplr error", "Could not retrieve '#{item}'.") end end end end
Revision: 9515
Updated Code
at November 11, 2008 00:38 by nighthawk
Updated Code
#!/usr/bin/ruby $: << ENV['TM_SUPPORT_PATH'] + '/lib' require "cgi" require "ui" require "xmlrpc/client" unless ENV['SNIPPLR_KEY'] TextMate::UI.alert(:critical, "Snipplr error", "Please first set your 'SNIPPLR_KEY' in Preferences > Advanced > Shell Variables.") exit end TextMate::UI.request_string(:title => "Get Snippet from Snipplr", :prompt => "Enter tags to search for:", :button1 => "Search") do |tag| begin server = XMLRPC::Client.new2("http://snipplr.com/xml-rpc.php") snippet_list = server.call('snippet.list', ENV['SNIPPLR_KEY'], tag, 'title') rescue # fall through end unless snippet_list and snippet_list.length > 0 TextMate::UI.alert(:warning, "Snipplr result", "No snippets for '#{tag}' found.") else items = {} snippet_list.each { |r| items[r['title']] = r['id'] } TextMate::UI.request_item(:items => items.keys.sort, :title => "Snipplr result", :prompt => "Choose", :string => "Select which snippet to paste") do |item| begin snippet = server.call('snippet.get', items[item]) puts CGI.unescapeHTML(snippet['source']) rescue TextMate::UI.alert(:critical, "Snipplr error", "Could not retrieve '#{item}'.") end end end end
Revision: 9514
Updated Code
at November 11, 2008 00:11 by nighthawk
Updated Code
#!/usr/bin/ruby $: << ENV['TM_SUPPORT_PATH'] + '/lib' require "ui" require "xmlrpc/client" unless ENV['SNIPPLR_KEY'] TextMate::UI.alert(:critical, "Snipplr error", "Please first set your 'SNIPPLR_KEY' in Preferences > Advanced > Shell Variables.") exit end TextMate::UI.request_string(:title => "Get Snippet from Snipplr", :prompt => "Enter tags to search for:", :button1 => "Search") do |tag| begin server = XMLRPC::Client.new2("http://snipplr.com/xml-rpc.php") snippet_list = server.call('snippet.list', ENV['SNIPPLR_KEY'], tag, 'title') rescue # fall through end unless snippet_list and snippet_list.length > 0 TextMate::UI.alert(:warning, "Snipplr result", "No snippets for '#{tag}' found.") else items = {} snippet_list.each { |r| items[r['title']] = r['id'] } TextMate::UI.request_item(:items => items.keys.sort, :title => "Snipplr result", :prompt => "Choose", :string => "Select which snippet to paste") do |item| begin snippet = server.call('snippet.get', items[item]) puts snippet['source'] rescue TextMate::UI.alert(:critical, "Snipplr error", "Could not retrieve '#{item}'.") end end end end
Revision: 9513
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at November 11, 2008 00:10 by nighthawk
Initial Code
#!/usr/bin/ruby $: << ENV['TM_SUPPORT_PATH'] + '/lib' require "ui" require "xmlrpc/client" unless ENV['SNIPPLR_KEY'] TextMate::UI.alert(:critical, "Snipplr error", "Please first set your 'SNIPPLR_KEY' in Preferences > Advanced > Shell Variables.") exit end TextMate::UI.request_string(:title => "Get Snippet from Snipplr", :prompt => "Enter tags to search for:", :button1 => "Search") do |tag| begin server = XMLRPC::Client.new2("http://snipplr.com/xml-rpc.php") snippet_list = server.call('snippet.list', ENV['SNIPPLR_KEY'], tag, 'title') rescue # fall through end unless snippet_list and snippet_list.length > 0 TextMate::UI.alert(:warning, "Snipplr result", "No snippets for '#{tag}' found.") else items = {} snippet_list.each { |r| items[r['title']] = r['id'] } TextMate::UI.request_item(:items => items.keys.sort, :title => "Snipplr result", :prompt => "Choose", :string => "Select which snippet to paste") do |item| begin snippet = server.call('snippet.get', items[item]) puts snippet['source'] rescue TextMate::UI.alert(:critical, "Snipplr error", "Could not retrieve '#{item}'.") end end end end
Initial URL
Initial Description
Initial Title
TextMate Ruby Snippet Retrieval
Initial Tags
command, textmate, ruby
Initial Language
Ruby