Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

• first version of the HyperLink Helper bundle. It has commands to wr…

…ap selection as a link, using a URL from the clipboard, lookup current word on Google, Yahoo, Wikipedia, etc. Currently templates are created for HTML, Markdown, Textile, and BBCode, which is also why all commands are scoped to these four languages.

git-svn-id: http://svn.textmate.org/trunk/Bundles/HyperLink Helper.tmbundle@6809 dfb7d73b-c2ec-0310-8fea-fb051d288c6d
  • Loading branch information...
commit 9118f688c82b3555c986d6fdadcfbef27991c10b 0 parents
@sorbits sorbits authored
45 Commands/Basic Wikipedia.tmCommand
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>nop</string>
+ <key>command</key>
+ <string>#!/usr/bin/env ruby
+require "#{ENV['TM_SUPPORT_PATH']}/lib/progress.rb"
+require "#{ENV['TM_SUPPORT_PATH']}/lib/exit_codes.rb"
+require 'open-uri'
+require 'erb'
+
+
+def getWikiDef(input)
+ TextMate.call_with_progress(:title =&gt; "Contacting Wikipedia", :message =&gt; "Looking for definition of #{input}") do
+ response = open("http://en.wikipedia.org/wiki/Special:Search?search=#{input}",
+ "User-Agent" =&gt; "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1",
+ "Referer" =&gt; "http://www.ruby-lang.org/") {|f| $response = f }
+ url = response.base_uri
+ # borrowed from iamrice.org
+ fp = open(url)
+ title = "Wikipedia Entry: " + fp.read.match(/&lt;title&gt;([^&lt;&gt;]*)&lt;\/title&gt;/i).to_a[1]
+ if title.include? "Search"
+ TextMate.exit_show_tool_tip "No definition found"
+ else
+ return title, url
+ end
+ end
+end
+input = STDIN.read
+title, url = getWikiDef(input)
+print ERB.new(ENV['TM_LINK_FORMAT']).result</string>
+ <key>input</key>
+ <string>selection</string>
+ <key>name</key>
+ <string>Basic Wikipedia</string>
+ <key>output</key>
+ <string>insertAsSnippet</string>
+ <key>scope</key>
+ <string>text.html, text.html.markdown, text.html.textile, text.bbcode</string>
+ <key>uuid</key>
+ <string>71C47F5F-41FA-40E8-A13A-238BC30984D1</string>
+</dict>
+</plist>
48 Commands/Lookup Word : Selection on Google and Link.tmCommand
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>nop</string>
+ <key>command</key>
+ <string>#!/usr/bin/env ruby
+# an evolution of the code from skiadas.dcostanet.net/afterthought
+# retrieves link from Google automatically and creates XHTML link
+# improved call to progress bar, added ability to retrieve title
+# of page and create title attribute in link using idea
+# borrowed from iamrice.org. Improved regex to handle title tags
+# newlines, spaces and capitalization differences
+require "#{ENV['TM_SUPPORT_PATH']}/lib/progress.rb"
+require 'net/http'
+require 'open-uri'
+require 'erb'
+
+def getLinkWithTitle(phrase)
+ TextMate.call_with_progress(:title =&gt; "Contacting Google", :message =&gt; "Retrieving Link for #{phrase}") do
+ response = Net::HTTP.get_response(URI.parse(URI.escape("http://www.google.com/search?q=#{phrase}&amp;btnI=I'm+Feeling+Lucky")))
+ url = response.to_hash['location'].first
+ fp = open(url)
+ title = fp.read.match(/&lt;title&gt;([^&lt;&gt;]*)&lt;\/title&gt;/i).to_a[1]
+ title = title.strip
+ return url, title, phrase
+ end
+end
+
+url, title, input = getLinkWithTitle(STDIN.read)
+print ERB.new(ENV['TM_LINK_FORMAT']).result</string>
+ <key>fallbackInput</key>
+ <string>word</string>
+ <key>input</key>
+ <string>selection</string>
+ <key>keyEquivalent</key>
+ <string>^@L</string>
+ <key>name</key>
+ <string>Lookup Word / Selection on Google and Link</string>
+ <key>output</key>
+ <string>insertAsSnippet</string>
+ <key>scope</key>
+ <string>text.html, text.html.markdown, text.html.textile, text.bbcode</string>
+ <key>uuid</key>
+ <string>D2F3BE59-1349-4762-9B17-A6F79A7F81B9</string>
+</dict>
+</plist>
110 Commands/Lookup Word : Selection on Wikipedia and link.tmCommand
@@ -0,0 +1,110 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>nop</string>
+ <key>bundleUUID</key>
+ <string>1BF76350-AB8F-4FC8-9512-1129CEEE0A3E</string>
+ <key>command</key>
+ <string>#!/usr/bin/env ruby
+require "#{ENV['TM_SUPPORT_PATH']}/lib/progress.rb"
+require "#{ENV['TM_SUPPORT_PATH']}/lib/exit_codes.rb"
+require "#{ENV['TM_SUPPORT_PATH']}/lib/dialog.rb"
+require 'cgi'
+require 'open-uri'
+require 'erb'
+
+def cap_all_words(string)
+ return string.split(" ").map{|w| w.capitalize}.join(" ")
+end
+
+def follow_redirect(page)
+ pagename = page.match(/var\swgPageName\s\=\s\"(.*?)\";/).to_a[1]
+ url = %{http://en.wikipedia.org/wiki/#{pagename}}
+ content = open(url).read
+ return url, content, pagename
+end #follow_redirect
+
+def select_link(links)
+ linklist = links.map { |p| p[0] }
+ item = Dialog.request_item :title =&gt; "Multiple Definitions", :prompt =&gt; "Please select a definition", :items =&gt; linklist
+ TextMate.exit_discard if item.nil?
+ return links[linklist.index(item)]
+end # select_link
+
+def check_for_search(page)
+ TextMate.exit_show_tool_tip "No definition found" if page.match(/&lt;title&gt;([^&lt;&gt;]*)&lt;\/title&gt;/i).to_a[1].include? "Search"
+ return page
+end # check_for_search
+
+def check_for_multiple_results(page,phrase,pagename)
+ if page.match(/(&lt;\/b&gt;\scan\sbe:&lt;\/p&gt;)|(&lt;\/b&gt;\smay\srefer\sto:&lt;\/p&gt;)/i) then
+ open("http://en.wikipedia.org/wiki/Special:Export/#{pagename}") {|body|
+ links = []
+ body.read.scan(/\[\[([^|\]]*)[|]?[^\]]*\]\]/) { |link|
+ links.push(link) }
+ choice = select_link(links)
+ TextMate.exit_discard if choice.nil?
+ TextMate.exit_replace_text(%{&lt;a href="http://en.wikipedia.org/wiki/#{CGI.escape(choice[0]).gsub('+','_')}" title="Wikipedia Entry: #{choice[0]}"&gt;#{phrase}&lt;/a&gt;})
+ }
+ end
+end #check_for_multiple_results
+
+def check_for_disambiguation(page,phrase,pagename)
+# if page.match(/#{phrase}[\s]?\(disambiguation\)/i) then
+ if page.include? "(disambiguation)"
+ # findlink = page.match(/\"(\/wiki\/#{pagename}_%28disambiguation%29)\"/i)
+ # open("http://en.wikipedia.org#{findlink[1]}") {|body|
+ open("http://en.wikipedia.org/wiki/Special:Export/#{pagename}_%28disambiguation%29") {|body|
+ content = body.read
+ links = []
+ content.scan(/\[\[([^|\]]*)[|]?[^\]]*\]\]/) { |link|
+ links.push(link) }
+ choice = select_link(links)
+ TextMate.exit_discard if choice.nil?
+ TextMate.exit_replace_text(%{&lt;a href="http://en.wikipedia.org/wiki/#{CGI.escape(choice[0]).gsub('+','_')}" title="Wikipedia Entry: #{choice[0]}"&gt;#{phrase}&lt;/a&gt;})
+ }
+ end
+end #check_for_disambiguation
+
+def getWikiDef(phrase)
+ TextMate.call_with_progress(:title =&gt; "Contacting Wikipedia", :message =&gt; "Looking for definition of #{phrase}") do
+ @response = open("http://en.wikipedia.org/wiki/Special:Search?search=#{CGI.escape(phrase)}",
+ "User-Agent" =&gt; "TextMate 1.5.3")
+ content = @response.read
+ if content.scan(/Redirected\sfrom/)
+ url, content, pagename = follow_redirect(content)
+ # confirmed = Dialog.request_confirmation :button1 =&gt; "Accept", :button2 =&gt; "Cancel", :title =&gt; "Redirected to \"#{pagename}\"", :prompt =&gt; "Accept Redirection?"
+ # TextMate.exit_discard unless confirmed
+ else
+ url = @response.base_uri
+ pagename = phrase
+ end
+ check_for_search(content)
+ check_for_multiple_results(content,phrase,pagename)
+ check_for_disambiguation(content,phrase,pagename)
+ title = "Wikipedia Entry: " + pagename
+ return url, title, phrase
+ end
+end
+
+url, title, input = getWikiDef(STDIN.read)
+print ERB.new(ENV['TM_LINK_FORMAT']).result
+</string>
+ <key>fallbackInput</key>
+ <string>word</string>
+ <key>input</key>
+ <string>selection</string>
+ <key>keyEquivalent</key>
+ <string>^@w</string>
+ <key>name</key>
+ <string>Lookup Word / Selection on Wikipedia and link</string>
+ <key>output</key>
+ <string>insertAsSnippet</string>
+ <key>scope</key>
+ <string>text.html, text.html.markdown, text.html.textile, text.bbcode</string>
+ <key>uuid</key>
+ <string>B94A2DF9-FC40-4281-80FB-35FB2917CDE7</string>
+</dict>
+</plist>
52 Commands/Wrap Selection as Link.tmCommand
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>nop</string>
+ <key>command</key>
+ <string>#!/usr/bin/env ruby -wKU
+require ENV['TM_SUPPORT_PATH'] + '/lib/escape.rb'
+require 'erb'
+
+def entity_escape(text)
+ text.gsub(/&amp;(?!([a-zA-Z0-9]+|#[0-9]+|#x[0-9a-fA-F]+);)/, '&amp;amp;')
+end
+
+def make_link(text)
+ case text
+ when %r{\A(mailto:)?(.*?@.*\..*)\z}:
+ "mailto:#{$2}"
+ when %r{http://www.(amazon.(?:com|co.uk|co.jp|ca|fr|de))/.+?/([A-Z0-9]{10})/[-a-zA-Z0-9_./%?=&amp;]+}:
+ "http://#{$1}/dp/#{$2}"
+ when %r{\A[a-zA-Z][a-zA-Z0-9.+-]*://.*\z}:
+ entity_escape(text)
+ when %r{\A(www\..*|.*\.(com|uk|net|org|info))\z}:
+ "http://#{entity_escape text}"
+ when %r{\A.*\.(com|uk|net|org|info)\z}:
+ "http://#{entity_escape text}"
+ when %r{\A\S+\z}:
+ entity_escape(text)
+ else
+ "http://some-site.com/"
+ end
+end
+
+url = make_link %x{__CF_USER_TEXT_ENCODING=$UID:0x8000100:0x8000100 pbpaste}.strip
+input = STDIN.read
+print ERB.new(ENV['TM_LINK_FORMAT']).result
+</string>
+ <key>input</key>
+ <string>selection</string>
+ <key>keyEquivalent</key>
+ <string>^L</string>
+ <key>name</key>
+ <string>Wrap Selection as Link</string>
+ <key>output</key>
+ <string>insertAsSnippet</string>
+ <key>scope</key>
+ <string>text.html, text.html.markdown, text.html.textile, text.bbcode</string>
+ <key>uuid</key>
+ <string>A42DC78E-6588-476F-8A00-40B8CCC6D2E0</string>
+</dict>
+</plist>
49 Commands/Yahoo News Search.tmCommand
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>nop</string>
+ <key>command</key>
+ <string>#!/usr/bin/env ruby -rjcode -Ku
+SUPPORT = ENV['TM_SUPPORT_PATH']
+DIALOG = ENV['DIALOG']
+require SUPPORT + '/lib/escape'
+require SUPPORT + '/lib/osx/plist'
+require SUPPORT + '/lib/exit_codes'
+require "#{ENV['TM_BUNDLE_SUPPORT']}/lib/yahoo"
+require 'erb'
+
+input = STDIN.read
+query = e_url(input)
+yahoo = NewsSearch.new('TM_YAHOO', query, 'all', 10, 1, nil, 1)
+ysuggest = []
+ yahoo.parse_results.each {|result|
+ ysuggest &lt;&lt; {
+ 'title' =&gt; result['Title'].gsub('"','&amp;raquo;'),
+ 'url' =&gt; result['Url']}
+ }
+ plist = { 'menuItems' =&gt; ysuggest }.to_plist
+
+ res = PropertyList::load(`#{e_sh DIALOG} -up #{e_sh plist}`)
+ TextMate.exit_show_tool_tip "No matches found" unless res.has_key? 'selectedMenuItem'
+ url = res['selectedMenuItem']['url']
+ title = res['selectedMenuItem']['title']
+
+ print ERB.new(ENV['TM_LINK_FORMAT']).result</string>
+ <key>fallbackInput</key>
+ <string>word</string>
+ <key>input</key>
+ <string>selection</string>
+ <key>keyEquivalent</key>
+ <string>^Y</string>
+ <key>name</key>
+ <string>Yahoo News Search</string>
+ <key>output</key>
+ <string>insertAsSnippet</string>
+ <key>scope</key>
+ <string>text.html, text.html.markdown, text.html.textile, text.bbcode</string>
+ <key>uuid</key>
+ <string>41D61EE6-B8A9-4C21-9ECE-E336588423DB</string>
+</dict>
+</plist>
44 Commands/Yahoo Related Suggestion.tmCommand
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>nop</string>
+ <key>command</key>
+ <string>#!/usr/bin/env ruby -rjcode -Ku
+SUPPORT = ENV['TM_SUPPORT_PATH']
+DIALOG = ENV['DIALOG']
+require SUPPORT + '/lib/escape'
+require SUPPORT + '/lib/osx/plist'
+require SUPPORT + '/lib/exit_codes'
+require "#{ENV['TM_BUNDLE_SUPPORT']}/lib/yahoo"
+
+input = STDIN.read
+query = e_url(input)
+yahoo = RelatedSuggestion.new('TM_YAHOO', query, 'all', 10, 1, nil, 1)
+ysuggest = []
+ yahoo.parse_analysis.each {|result|
+ ysuggest &lt;&lt; {
+ 'title' =&gt; result}
+ }
+ plist = { 'menuItems' =&gt; ysuggest }.to_plist
+
+ res = PropertyList::load(`#{e_sh DIALOG} -up #{e_sh plist}`)
+ abort unless res.has_key? 'selectedMenuItem'
+ TextMate.exit_replace_text res['selectedMenuItem']['title']</string>
+ <key>fallbackInput</key>
+ <string>word</string>
+ <key>input</key>
+ <string>selection</string>
+ <key>keyEquivalent</key>
+ <string>^Y</string>
+ <key>name</key>
+ <string>Yahoo Related Suggestion</string>
+ <key>output</key>
+ <string>replaceSelectedText</string>
+ <key>scope</key>
+ <string>text.html, text.html.markdown, text.html.textile, text.bbcode</string>
+ <key>uuid</key>
+ <string>6511380B-D4C7-408B-85FF-9E98C6AAEB4A</string>
+</dict>
+</plist>
49 Commands/Yahoo Video Search.tmCommand
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>nop</string>
+ <key>command</key>
+ <string>#!/usr/bin/env ruby -rjcode -Ku
+SUPPORT = ENV['TM_SUPPORT_PATH']
+DIALOG = ENV['DIALOG']
+require SUPPORT + '/lib/escape'
+require SUPPORT + '/lib/osx/plist'
+require SUPPORT + '/lib/exit_codes'
+require "#{ENV['TM_BUNDLE_SUPPORT']}/lib/yahoo"
+require 'erb'
+
+input = STDIN.read
+query = e_url(input)
+yahoo = VideoSearch.new('TM_YAHOO', query, 'all', 10, 1, nil, 1)
+ysuggest = []
+ yahoo.parse_results.each {|result|
+ ysuggest &lt;&lt; {
+ 'title' =&gt; result['Title'].gsub('"','&amp;raquo;'),
+ 'url' =&gt; result['Url']}
+ }
+ plist = { 'menuItems' =&gt; ysuggest }.to_plist
+
+ res = PropertyList::load(`#{e_sh DIALOG} -up #{e_sh plist}`)
+ TextMate.exit_show_tool_tip "No matches found" unless res.has_key? 'selectedMenuItem'
+ url = res['selectedMenuItem']['url']
+ title = res['selectedMenuItem']['title']
+
+ print ERB.new(ENV['TM_LINK_FORMAT']).result</string>
+ <key>fallbackInput</key>
+ <string>word</string>
+ <key>input</key>
+ <string>selection</string>
+ <key>keyEquivalent</key>
+ <string>^Y</string>
+ <key>name</key>
+ <string>Yahoo Video Search</string>
+ <key>output</key>
+ <string>insertAsSnippet</string>
+ <key>scope</key>
+ <string>text.html, text.html.markdown, text.html.textile, text.bbcode</string>
+ <key>uuid</key>
+ <string>50A08D59-18D6-48C1-938D-6644906F5C83</string>
+</dict>
+</plist>
49 Commands/Yahoo Web Search.tmCommand
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>beforeRunningCommand</key>
+ <string>nop</string>
+ <key>command</key>
+ <string>#!/usr/bin/env ruby -rjcode -Ku
+SUPPORT = ENV['TM_SUPPORT_PATH']
+DIALOG = ENV['DIALOG']
+require SUPPORT + '/lib/escape'
+require SUPPORT + '/lib/osx/plist'
+require SUPPORT + '/lib/exit_codes'
+require "#{ENV['TM_BUNDLE_SUPPORT']}/lib/yahoo"
+require 'erb'
+
+input = STDIN.read
+query = e_url(input)
+yahoo = WebSearch.new('TM_YAHOO', query, 'all', 10, 1, nil, 1)
+ysuggest = []
+ yahoo.parse_results.each {|result|
+ ysuggest &lt;&lt; {
+ 'title' =&gt; result['Title'].gsub('"','&amp;raquo;'),
+ 'url' =&gt; result['Url']}
+ }
+ plist = { 'menuItems' =&gt; ysuggest }.to_plist
+
+ res = PropertyList::load(`#{e_sh DIALOG} -up #{e_sh plist}`)
+ TextMate.exit_show_tool_tip "No matches found" unless res.has_key? 'selectedMenuItem'
+ url = res['selectedMenuItem']['url']
+ title = res['selectedMenuItem']['title']
+
+ print ERB.new(ENV['TM_LINK_FORMAT']).result</string>
+ <key>fallbackInput</key>
+ <string>word</string>
+ <key>input</key>
+ <string>selection</string>
+ <key>keyEquivalent</key>
+ <string>^Y</string>
+ <key>name</key>
+ <string>Yahoo Web Search</string>
+ <key>output</key>
+ <string>insertAsSnippet</string>
+ <key>scope</key>
+ <string>text.html, text.html.markdown, text.html.textile, text.bbcode</string>
+ <key>uuid</key>
+ <string>2E03E8C8-DC99-4D15-AE46-0E8DCE6BBE6F</string>
+</dict>
+</plist>
24 Preferences/Bulletin Board.tmPreferences
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>name</key>
+ <string>Bulletin Board</string>
+ <key>scope</key>
+ <string>text.bbcode</string>
+ <key>settings</key>
+ <dict>
+ <key>shellVariables</key>
+ <array>
+ <dict>
+ <key>name</key>
+ <string>TM_LINK_FORMAT</string>
+ <key>value</key>
+ <string>[URL=&lt;%= e_sn url %&gt;]&lt;%= e_sn input %&gt;[/URL]</string>
+ </dict>
+ </array>
+ </dict>
+ <key>uuid</key>
+ <string>8CCCD8B6-9583-4B5D-8CBF-0867B14E86D7</string>
+</dict>
+</plist>
22 Preferences/Fallback (not supported).tmPreferences
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>name</key>
+ <string>Fallback (not supported)</string>
+ <key>settings</key>
+ <dict>
+ <key>shellVariables</key>
+ <array>
+ <dict>
+ <key>name</key>
+ <string>TM_LINK_FORMAT</string>
+ <key>value</key>
+ <string>(this language is not supported, see … for more info)</string>
+ </dict>
+ </array>
+ </dict>
+ <key>uuid</key>
+ <string>CA3F1BC7-8F8A-464F-BC3A-322B437F9E8E</string>
+</dict>
+</plist>
24 Preferences/HTML.tmPreferences
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>name</key>
+ <string>HTML</string>
+ <key>scope</key>
+ <string>text.html</string>
+ <key>settings</key>
+ <dict>
+ <key>shellVariables</key>
+ <array>
+ <dict>
+ <key>name</key>
+ <string>TM_LINK_FORMAT</string>
+ <key>value</key>
+ <string>&lt;a href="&lt;%= e_sn url %&gt;"&lt;%= " title='\${1:#{e_sn title}}'" if defined? title %&gt;&gt;&lt;%= e_sn input %&gt;&lt;/a&gt;</string>
+ </dict>
+ </array>
+ </dict>
+ <key>uuid</key>
+ <string>7D88D7CF-AC5B-491E-801F-FD5AC1F525CB</string>
+</dict>
+</plist>
24 Preferences/Markdown.tmPreferences
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>name</key>
+ <string>Markdown</string>
+ <key>scope</key>
+ <string>text.html.markdown</string>
+ <key>settings</key>
+ <dict>
+ <key>shellVariables</key>
+ <array>
+ <dict>
+ <key>name</key>
+ <string>TM_LINK_FORMAT</string>
+ <key>value</key>
+ <string>[&lt;%= e_sn input %&gt;](&lt;%= e_sn url %&gt;&lt;%= " \"${1:#{e_sn title}}\"" if defined? title %&gt;)</string>
+ </dict>
+ </array>
+ </dict>
+ <key>uuid</key>
+ <string>86084226-4371-4593-BC83-FF2023817BCD</string>
+</dict>
+</plist>
24 Preferences/Textile.tmPreferences
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>name</key>
+ <string>Textile</string>
+ <key>scope</key>
+ <string>text.html.textile</string>
+ <key>settings</key>
+ <dict>
+ <key>shellVariables</key>
+ <array>
+ <dict>
+ <key>name</key>
+ <string>TM_LINK_FORMAT</string>
+ <key>value</key>
+ <string>"&lt;%= e_sn input %&gt;":&lt;%= e_sn url %&gt;</string>
+ </dict>
+ </array>
+ </dict>
+ <key>uuid</key>
+ <string>F514F82B-9C65-46BA-B264-D2F374372C54</string>
+</dict>
+</plist>
548 Support/lib/yahoo.rb
@@ -0,0 +1,548 @@
+#/usr/local/bin/ruby
+
+##
+# Ruby API for Yahoo! Search Web Services
+# See http://developer.yahoo.net/
+# (C) 2005 Premshree Pillai
+# http://www.livejournal.com/~premshree
+#
+# LICENSE: BSD(-compatible)
+#
+# EXAMPLE:
+# - <tt>obj = WebSearch.new('YOUR-APP_ID', 'query')</tt>
+# - <tt>obj.parse_results</tt> #returns a result hash
+#
+# see code to understand stuff
+#
+# HISTORY:
+# - 0.2 JUN-29-2005:
+# - MyWeb2 support (tag search, url search, related tags)
+# - 0.1 MAR-01-2005: Initial release
+#
+# BUGS? premshree at gmail dot com
+#
+# TODO:
+# - Clean-up code
+# - Refactor
+# - Change complete design?
+##
+
+require 'net/http'
+require 'rexml/document'
+include REXML
+
+$AUTHOR = "Premshree Pillai"
+$VERSION = "0.2"
+$DATE = "2005-06-29 10:12"
+
+$SERVICES = {
+ 'video_search' => ['VideoSearchService', 'videoSearch', 'Video Search'],
+ 'image_search' => ['ImageSearchService', 'imageSearch', 'Image Search'],
+ 'web_search' => ['WebSearchService', 'webSearch', 'Web Search'],
+ 'news_search' => ['NewsSearchService', 'newsSearch', 'News Search'],
+ 'web_related' => ['WebSearchService', 'relatedSuggestion', 'Web Search Related Suggestion'],
+ 'spelling' => ['WebSearchService', 'spellingSuggestion', 'Web Search Spelling Suggestion'],
+ 'myweb2_url' => ['MyWebService', 'urlSearch', 'URL search'],
+ 'myweb2_tag' => ['MyWebService', 'tagSearch', 'Tag search'],
+ 'myweb2_related' => ['MyWebService', 'relatedTags', 'Related tags'],
+ 'tag_analysis' => ['ContentAnalysisService', 'termExtraction', 'Tag Analysis']
+}
+
+class Search
+ def initialize(app_id)
+ @NAME = "Search"
+ @SERVICE = "Search"
+ @PROTOCOL = "http"
+ @SERVER = "api.search.yahoo.com"
+ @VERSION = "V1"
+ @NEXT_QID = 1
+
+ #super(_Search, self).__init__(debug)
+ @service = { "name" => @NAME,
+ "protocol" => @PROTOCOL,
+ "server" => @SERVER,
+ "version" => @VERSION,
+ "service" => @SERVICE }
+
+ @app_id = app_id
+ @valid_params = {}
+
+ @qid = @NEXT_QID
+ @NEXT_QID = @NEXT_QID + 1
+
+ init_valid_params()
+ reset()
+ end
+
+ def init_valid_params()
+ # todo
+ end
+
+ def reset()
+ @params = {}
+ @url = nil
+ end
+
+ def get_svc_name()
+ return @service["name"]
+ end
+ def set_svc_name(value)
+ @service["name"] = value
+ end
+
+ def get_svc_protocol()
+ return @service["protocol"]
+ end
+ def set_svc_protocol(value)
+ @service["protocol"] = value
+ end
+
+ def get_svc_service()
+ return @service["service"]
+ end
+ def set_svc_service(value)
+ @service["service"] = value
+ end
+
+ def get_svc_server()
+ return @service["server"]
+ end
+ def set_svc_server(value)
+ @service["server"] = value
+ end
+
+ def get_svc_version()
+ return @service["version"]
+ end
+ def set_svc_version(value)
+ @service["version"] = value
+ end
+
+ def get_app_id()
+ return @app_id
+ end
+ def set_app_id(app_id)
+ if app_id.class.to_s == 'String' and app_id =~ /^[a-zA-Z0-9 _()\[\]*+\-=,.:\\\@]{8,40}$/
+ begin
+ @app_id = app_id
+ #update(@params, {'app_id' => @app_id})
+ rescue
+ p "'app_id' can only contain a-zA-Z0-9 _()\[\]*+\-=,.:\\\@"
+ end
+ end
+ end
+
+ def set_params(args)
+ args.each { |param, value|
+ set_param(param, value)
+ }
+ end
+
+ def get_param(param)
+ if @params.keys.include?(param)
+ return @params[param]
+ else
+ return @valid_params[param][1]
+ end
+ end
+
+ def set_param(param, value)
+ @params[param] = value
+ end
+
+ def update(var, hsh)
+ hsh.each { |param, value|
+ var[param] = value
+ }
+ end
+ def encode_params()
+ encoded_params = ''
+ @params.each { |param, value|
+ encoded_params = encoded_params + "#{param}=#{value}&"
+ }
+ return encoded_params
+ end
+
+ def get_valid_params()
+ return @valid_params.keys
+ end
+
+ def get_url()
+ params = @params
+ update(@params, {"appid" => @app_id})
+ @url = "#{@service['protocol']}://#{@service['server']}/#{@service['service']}/#{@service['version']}/#{@service['name']}?" + encode_params
+ return @url
+ end
+
+ def open()
+ url = get_url()
+ #p url
+ resp = Net::HTTP.get_response(URI.parse(url))
+ @data = resp.body
+ return @data
+ end
+ def parse_analysis()
+ open()
+ doc = Document.new(@data)
+ results = []
+ doc.elements.each('ResultSet/Result') {|element|
+ results << element.text
+ }
+ return results
+ end
+ def parse_results()
+ open()
+ xml_string = @data
+ doc = Document.new(xml_string)
+ results = []
+ results_nos = []
+ results_titles = []
+ results_summaries = []
+ results_urls = []
+ results_clickurls = []
+ results_moddates = []
+ results_mimetypes = []
+
+ # myweb2
+ results_users = []
+ results_notes = []
+ results_dates = []
+ results_tags = []
+ results_freqs = []
+
+ doc.elements.each('ResultSet/Result') { |element|
+ results_nos << ''
+ }
+ doc.elements.each('ResultSet/Result/Title') { |element|
+ results_titles << element.text
+ }
+ doc.elements.each('ResultSet/Result/Summary') { |element|
+ results_summaries << element.text
+ }
+ doc.elements.each('ResultSet/Result/Url') { |element|
+ results_urls << element.text
+ }
+ doc.elements.each('ResultSet/Result/ClickUrl') { |element|
+ results_clickurls << element.text
+ }
+ doc.elements.each('ResultSet/Result/ModificationDate') { |element|
+ results_moddates << element.text
+ }
+ doc.elements.each('ResultSet/Result/MimeType') { |element|
+ results_mimetypes << element.text
+ }
+ doc.elements.each('ResultSet/Result/User') { |element|
+ results_users << element.text
+ }
+ doc.elements.each('ResultSet/Result/Note') { |element|
+ results_notes << element.text
+ }
+ doc.elements.each('ResultSet/Result/Date') { |element|
+ results_dates << element.text
+ }
+ doc.elements.each('ResultSet/Result/Tag') { |element|
+ results_tags << element.text
+ }
+ doc.elements.each('ResultSet/Result/Frequency') { |element|
+ results_freqs << element.text
+ }
+ count = 0
+ results_nos.length.times {
+ # TODO: return keys that have values
+ results << {
+ 'Title' => results_titles[count],
+ 'Summary' => results_summaries[count],
+ 'Url' => results_urls[count],
+ 'ClickUrl' => results_clickurls[count],
+ 'ModificationDate' => results_moddates[count],
+ 'MimeType' => results_mimetypes[count],
+ 'User' => results_users[count],
+ 'Note' => results_notes[count],
+ 'Date' => results_dates[count],
+ 'Tag' => results_tags[count],
+ 'Frequency' => results_freqs[count],
+ }
+ count = count + 1
+ }
+ return results
+ end
+
+ # basic parameters
+ def get_query()
+ return get_param("query")
+ end
+ def set_query(value)
+ set_param("query", value)
+ end
+
+ def set_context(value)
+ set_param("context", value)
+ end
+
+ def get_results()
+ return get_param("results")
+ end
+ def set_results(value)
+ set_param("results", value)
+ end
+
+ def get_start()
+ return get_param("start")
+ end
+ def set_start(value)
+ set_param("start", value)
+ end
+
+ def set_tag(value)
+ set_param("tag", value)
+ end
+
+ def set_yid(value)
+ set_param("yid", value)
+ end
+
+ def set_sort(value)
+ set_param("sort", value)
+ end
+
+ def set_reverse_sort(value)
+ set_param("reverse_sort", value)
+ end
+
+ def set_url(value)
+ set_param("url", value)
+ end
+
+ # common params
+ def get_type()
+ return get_param("type")
+ end
+ def set_type(value)
+ set_param("type", value)
+ end
+
+ def get_format()
+ return get_param("format")
+ end
+ def set_format(value)
+ set_param("format", value)
+ end
+
+ def get_adult_ok()
+ return get_param("adult_ok")
+ end
+ def set_adult_ok(value)
+ set_param("adult_ok", value)
+ end
+end
+
+
+
+class VideoSearch < Search
+ def initialize(app_id, query, type='all', results=10, start=1, format=nil, adult_ok=0)
+ super Search
+ set_app_id(app_id)
+ set_svc_service($SERVICES['video_search'][0])
+ set_svc_name($SERVICES['video_search'][1])
+ set_query(query)
+ set_type(type)
+ set_results(results)
+ set_start(start)
+ set_format(format)
+ set_adult_ok(adult_ok)
+ end
+end
+
+
+
+class ImageSearch < Search
+ def initialize(app_id, query, type='all', results=10, start=1, format=nil, adult_ok=0)
+ super Search
+ set_app_id(app_id)
+ set_svc_service($SERVICES['image_search'][0])
+ set_svc_name($SERVICES['image_search'][1])
+ set_query(query)
+ set_type(type)
+ set_results(results)
+ set_start(start)
+ set_format(format)
+ set_adult_ok(adult_ok)
+ end
+end
+
+
+
+class WebSearch < Search
+ def initialize(app_id, query, type='all', results=10, start=1, format=nil, adult_ok=0)
+ super Search
+ set_app_id(app_id)
+ set_svc_service($SERVICES['web_search'][0])
+ set_svc_name($SERVICES['web_search'][1])
+ set_query(query)
+ set_type(type)
+ set_results(results)
+ set_start(start)
+ set_format(format)
+ set_adult_ok(adult_ok)
+ end
+
+ def get_similar_ok()
+ return get_param("similar_ok")
+ end
+ def set_similar_ok(value)
+ set_param("similar_ok", value)
+ end
+
+ def get_language()
+ return get_param("language")
+ end
+ def set_language(value)
+ set_param("language", value)
+ end
+end
+
+class TagAnalysis < Search
+ def initialize(app_id, context, type='all', results=10, start=1, format=nil, adult_ok=1)
+ super Search
+ set_app_id(app_id)
+ set_svc_service($SERVICES['tag_analysis'][0])
+set_svc_name($SERVICES['tag_analysis'][1])
+set_context(context)
+set_type(type)
+set_results(results)
+set_start(start)
+set_format(format)
+set_adult_ok(adult_ok)
+ end
+end
+
+class NewsSearch < Search
+ def initialize(app_id, query, type='all', results=10, start=1, format=nil, adult_ok=0)
+ super Search
+ set_app_id(app_id)
+ set_svc_service($SERVICES['news_search'][0])
+ set_svc_name($SERVICES['news_search'][1])
+ set_query(query)
+ set_type(type)
+ set_results(results)
+ set_start(start)
+ set_format(format)
+ set_adult_ok(adult_ok)
+ end
+
+
+ def get_type()
+ return get_param("type")
+ end
+ def set_type(value)
+ set_param("type", value)
+ end
+
+ def get_sort()
+ return get_param("sort")
+ end
+ def set_sort(value)
+ set_param("sort", value)
+ end
+
+ def get_language()
+ return get_param("language")
+ end
+ def set_language(value)
+ set_param("language", value)
+ end
+end
+
+
+
+class RelatedSuggestion < Search
+ def initialize(app_id, query, type='all', results=10, start=1, format=nil, adult_ok=0)
+ super Search
+ set_app_id(app_id)
+ set_svc_service($SERVICES['web_related'][0])
+ set_svc_name($SERVICES['web_related'][1])
+ set_query(query)
+ set_type(type)
+ set_results(results)
+ set_start(start)
+ set_format(format)
+ set_adult_ok(adult_ok)
+ end
+end
+
+
+
+class SpellingSuggestion < Search
+ def initialize(app_id, query, type='all', results=10, start=1, format=nil, adult_ok=0)
+ super Search
+ set_app_id(app_id)
+ set_svc_service($SERVICES['spelling'][0])
+ set_svc_name($SERVICES['spelling'][1])
+ set_query(query)
+ set_type(type)
+ set_results(results)
+ set_start(start)
+ set_format(format)
+ set_adult_ok(adult_ok)
+ end
+
+ def get_query()
+ return get_param("query")
+ end
+ def set_query(value)
+ set_param("query",value)
+ end
+end
+
+
+##
+# MyWeb2
+##
+class UrlSearch < Search
+ def initialize(app_id, tag, yahooid='', sort='date', reverse_sort=0, results=10, start=1)
+ super Search
+ set_app_id(app_id)
+ set_svc_service($SERVICES['myweb2_url'][0])
+ set_svc_name($SERVICES['myweb2_url'][1])
+ set_tag(tag)
+ set_yid(yahooid)
+ set_sort(sort)
+ set_reverse_sort(reverse_sort)
+ set_results(results)
+ set_start(start)
+ end
+end
+
+
+
+class TagSearch < Search
+ def initialize(app_id, url, yahooid='', sort='date', reverse_sort=0, results=10, start=1)
+ super Search
+ set_app_id(app_id)
+ set_svc_service($SERVICES['myweb2_tag'][0])
+ set_svc_name($SERVICES['myweb2_tag'][1])
+ set_url(url)
+ set_yid(yahooid)
+ set_sort(sort)
+ set_reverse_sort(reverse_sort)
+ set_results(results)
+ set_start(start)
+ end
+end
+
+
+
+class RelatedTags < Search
+ def initialize(app_id, tag, yahooid='', sort='date', reverse_sort=0, results=10, start=1)
+ super Search
+ set_app_id(app_id)
+ set_svc_service($SERVICES['myweb2_related'][0])
+ set_svc_name($SERVICES['myweb2_related'][1])
+ set_tag(tag)
+ set_yid(yahooid)
+ set_sort(sort)
+ set_reverse_sort(reverse_sort)
+ set_results(results)
+ set_start(start)
+ end
+end
51 info.plist
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>contactEmailRot13</key>
+ <string>oergg@pvepyrfvkqrfvta.pbz</string>
+ <key>contactName</key>
+ <string>Brett Terpstra</string>
+ <key>description</key>
+ <string>The commands in this bundle makes it easy to create hyper links for example by searching for the current word or using the clipboard contents. This bundle is much more useful than it sounds!</string>
+ <key>mainMenu</key>
+ <dict>
+ <key>items</key>
+ <array>
+ <string>A42DC78E-6588-476F-8A00-40B8CCC6D2E0</string>
+ <string>------------------------------------</string>
+ <string>D2F3BE59-1349-4762-9B17-A6F79A7F81B9</string>
+ <string>B94A2DF9-FC40-4281-80FB-35FB2917CDE7</string>
+ <string>------------------------------------</string>
+ <string>2E03E8C8-DC99-4D15-AE46-0E8DCE6BBE6F</string>
+ <string>6511380B-D4C7-408B-85FF-9E98C6AAEB4A</string>
+ <string>41D61EE6-B8A9-4C21-9ECE-E336588423DB</string>
+ <string>50A08D59-18D6-48C1-938D-6644906F5C83</string>
+ <string>------------------------------------</string>
+ <string>71C47F5F-41FA-40E8-A13A-238BC30984D1</string>
+ </array>
+ <key>submenus</key>
+ <dict/>
+ </dict>
+ <key>name</key>
+ <string>HyperLink Helper</string>
+ <key>ordering</key>
+ <array>
+ <string>71C47F5F-41FA-40E8-A13A-238BC30984D1</string>
+ <string>D2F3BE59-1349-4762-9B17-A6F79A7F81B9</string>
+ <string>B94A2DF9-FC40-4281-80FB-35FB2917CDE7</string>
+ <string>41D61EE6-B8A9-4C21-9ECE-E336588423DB</string>
+ <string>6511380B-D4C7-408B-85FF-9E98C6AAEB4A</string>
+ <string>50A08D59-18D6-48C1-938D-6644906F5C83</string>
+ <string>2E03E8C8-DC99-4D15-AE46-0E8DCE6BBE6F</string>
+ <string>A42DC78E-6588-476F-8A00-40B8CCC6D2E0</string>
+ <string>CA3F1BC7-8F8A-464F-BC3A-322B437F9E8E</string>
+ <string>8CCCD8B6-9583-4B5D-8CBF-0867B14E86D7</string>
+ <string>7D88D7CF-AC5B-491E-801F-FD5AC1F525CB</string>
+ <string>86084226-4371-4593-BC83-FF2023817BCD</string>
+ <string>F514F82B-9C65-46BA-B264-D2F374372C54</string>
+ </array>
+ <key>uuid</key>
+ <string>7592B521-FC5E-4D69-A6DD-5A0DD7529CB4</string>
+</dict>
+</plist>
Please sign in to comment.
Something went wrong with that request. Please try again.