Hi everybody.
As some of you may have figured out, I work a lot in HTML and CSS and I have a fetish for descriptive titles on links. I've been rewriting the wrap selection as link command and have it all worked out to grab the title of the link in the clipboard if it starts with http(s). I can't get it to validate the link, though.
Here's the text of the command:
#!/usr/bin/env ruby require "#{ENV['TM_SUPPORT_PATH']}/lib/progress.rb" require 'open-uri' link = "http://site.com" title = #{ENV['TM_SELECTED_TEXT']} s = IO.popen('pbpaste', 'r+').read if s.match(/(http(s?)://)/) then TextMate.call_with_progress(:title => "Opening Link", :message => "Retrieving Title for #{s}") do begin fp = open(s) title = fp.read.match(/<title>([^<>]*)</title>/i).to_a [1].strip link = s rescue title = "site unreachable" end end end print %{<a href="${1:#{link}}" title="${2:#{title}}" > $TM_SELECTED_TEXT</a>}
I've tried all kinds of overly complex methods that all yield the same results when the link is bogus:
/usr/lib/ruby/1.8/timeout.rb:42:in /bin/bash: -c: line 1: unexpected EOF while looking for matching `'' /bin/bash: -c: line 3: syntax error: unexpected end of fileconnect' from /usr/lib/ruby/1.8/net/protocol.rb:64:in /bin/bash: -c: line 1: unexpected EOF while looking for matching `'' /bin/bash: -c: line 3: syntax error: unexpected end of fileopen' from /usr/lib/ruby/1.8/net/http.rb:430:in /bin/bash: -c: line 1: unexpected EOF while looking for matching `'' /bin/bash: -c: line 3: syntax error: unexpected end of filestart' from /usr/lib/ruby/1.8/net/http.rb:324:in /bin/bash: -c: line 1: unexpected EOF while looking for matching `'' /bin/bash: -c: line 3: syntax error: unexpected end of fileproxy_open' from /usr/lib/ruby/1.8/open-uri.rb:525:in /bin/bash: -c: line 1: unexpected EOF while looking for matching `'' /bin/bash: -c: line 5: syntax error: unexpected end of filepopen' from /Users/brett/Library/Application Support/TextMate/Support/lib/ progress.rb:11:in This is what I get (and should get, I think) when I run it from a Ruby dialog: <a href="${1:http://site.com}" title="${2:site unreachable}" > $TM_SELECTED_TEXT</a>
It works great when the site in the clipboard is valid. Any suggestions would be appreciated.
Thanks, Brett
Brett Terpstra : Art Director Circle Six Design, Inc. 111 Riverfront Dr, Suite 204
Probably use net::http to grab the page, and use the response codes to fail gracefully. Otherwise test for a valid response using curl before calling open?
On Oct 22, 2006, at 11:00 AM, Brett Terpstra wrote:
Hi everybody.
As some of you may have figured out, I work a lot in HTML and CSS and I have a fetish for descriptive titles on links. I've been rewriting the wrap selection as link command and have it all worked out to grab the title of the link in the clipboard if it starts with http(s). I can't get it to validate the link, though.
Here's the text of the command:
#!/usr/bin/env ruby require "#{ENV['TM_SUPPORT_PATH']}/lib/progress.rb" require 'open-uri' link = "http://site.com" title = #{ENV['TM_SELECTED_TEXT']} s = IO.popen('pbpaste', 'r+').read if s.match(/(http(s?)://)/) then TextMate.call_with_progress(:title => "Opening Link", :message => "Retrieving Title for #{s}") do begin fp = open(s) title = fp.read.match(/<title>([^<>]*)</title>/i).to_a [1].strip link = s rescue title = "site unreachable" end end end print %{<a href="${1:#{link}}" title="${2:#{title}}" > $TM_SELECTED_TEXT</a>}
I've tried all kinds of overly complex methods that all yield the same results when the link is bogus:
/usr/lib/ruby/1.8/timeout.rb:42:in /bin/bash: -c: line 1: unexpected EOF while looking for matching `'' /bin/bash: -c: line 3: syntax error: unexpected end of fileconnect' from /usr/lib/ruby/1.8/net/protocol.rb:64:in /bin/bash: -c: line 1: unexpected EOF while looking for matching `'' /bin/bash: -c: line 3: syntax error: unexpected end of fileopen' from /usr/lib/ruby/1.8/net/http.rb:430:in /bin/bash: -c: line 1: unexpected EOF while looking for matching `'' /bin/bash: -c: line 3: syntax error: unexpected end of filestart' from /usr/lib/ruby/1.8/net/http.rb:324:in /bin/bash: -c: line 1: unexpected EOF while looking for matching `'' /bin/bash: -c: line 3: syntax error: unexpected end of fileproxy_open' from /usr/lib/ruby/1.8/open-uri.rb:525:in /bin/bash: -c: line 1: unexpected EOF while looking for matching `'' /bin/bash: -c: line 5: syntax error: unexpected end of filepopen' from /Users/brett/Library/Application Support/TextMate/Support/lib/ progress.rb:11:in This is what I get (and should get, I think) when I run it from a Ruby dialog:
<a href="${1:http://site.com}" title="${2:site unreachable}" > $TM_SELECTED_TEXT</a>
It works great when the site in the clipboard is valid. Any suggestions would be appreciated.
Thanks, Brett
Brett Terpstra : Art Director Circle Six Design, Inc. 111 Riverfront Dr, Suite 204
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
I'll try curl. I already tried a whole slew of net:http header checks and they all gave me that same error. The weird thing is that if I paste the script into an edit window and hit CTRL-R, it runs fine... just won't run as a command.
Thanks, Brett
On Oct 22, 2006, at 11:07 AM, Reprisal wrote:
Probably use net::http to grab the page, and use the response codes to fail gracefully. Otherwise test for a valid response using curl before calling open?
On Oct 22, 2006, at 11:00 AM, Brett Terpstra wrote:
Hi everybody.
As some of you may have figured out, I work a lot in HTML and CSS and I have a fetish for descriptive titles on links. I've been rewriting the wrap selection as link command and have it all worked out to grab the title of the link in the clipboard if it starts with http(s). I can't get it to validate the link, though.
Here's the text of the command:
#!/usr/bin/env ruby require "#{ENV['TM_SUPPORT_PATH']}/lib/progress.rb" require 'open-uri' link = "http://site.com" title = #{ENV['TM_SELECTED_TEXT']} s = IO.popen('pbpaste', 'r+').read if s.match(/(http(s?)://)/) then TextMate.call_with_progress(:title => "Opening Link", :message => "Retrieving Title for #{s}") do begin fp = open(s) title = fp.read.match(/<title>([^<>]*)</title>/i).to_a [1].strip link = s rescue title = "site unreachable" end end end print %{<a href="${1:#{link}}" title="${2:#{title}}" > $TM_SELECTED_TEXT</a>}
I've tried all kinds of overly complex methods that all yield the same results when the link is bogus:
/usr/lib/ruby/1.8/timeout.rb:42:in /bin/bash: -c: line 1: unexpected EOF while looking for matching `'' /bin/bash: -c: line 3: syntax error: unexpected end of fileconnect' from /usr/lib/ruby/1.8/net/protocol.rb:64:in /bin/bash: -c: line 1: unexpected EOF while looking for matching `'' /bin/bash: -c: line 3: syntax error: unexpected end of fileopen' from /usr/lib/ruby/1.8/net/http.rb:430:in /bin/bash: -c: line 1: unexpected EOF while looking for matching `'' /bin/bash: -c: line 3: syntax error: unexpected end of filestart' from /usr/lib/ruby/1.8/net/http.rb:324:in /bin/bash: -c: line 1: unexpected EOF while looking for matching `'' /bin/bash: -c: line 3: syntax error: unexpected end of fileproxy_open' from /usr/lib/ruby/1.8/open-uri.rb:525:in /bin/bash: -c: line 1: unexpected EOF while looking for matching `'' /bin/bash: -c: line 5: syntax error: unexpected end of filepopen' from /Users/brett/Library/Application Support/TextMate/Support/lib/ progress.rb:11:in This is what I get (and should get, I think) when I run it from a Ruby dialog:
<a href="${1:http://site.com}" title="${2:site unreachable}" > $TM_SELECTED_TEXT</a>
It works great when the site in the clipboard is valid. Any suggestions would be appreciated.
Thanks, Brett
Brett Terpstra : Art Director Circle Six Design, Inc. 111 Riverfront Dr, Suite 204
_ For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
The version from textmate itself was just i little bit too basic. Here's my simplified version...
<a href="${1:` # if the clipboard contains a single line, let’s use that export __CF_USER_TEXT_ENCODING=$UID:0x8000100:0x8000100 if [[ $(pbpaste|wc -l) -eq 0 ]] then pbpaste|perl -pe 's/&(?!([a-zA-Z0-9]+|#[0-9]+|#x[0-9a-fA- F]+);)/&/g' else echo http://site.com/ fi `}" ${2:target="${3:_blank}"} ${4:title="${5:${TM_SELECTED_TEXT:Link text...}}"}>${6:${TM_SELECTED_TEXT:Link text...}}</a>$0
For sure their can be made some changes .. so i'll listen carefully :-)
Regards J.
On 22-okt-2006, at 18:12, Brett Terpstra wrote:
I'll try curl. I already tried a whole slew of net:http header checks and they all gave me that same error. The weird thing is that if I paste the script into an edit window and hit CTRL-R, it runs fine... just won't run as a command.
Thanks, Brett
On Oct 22, 2006, at 11:07 AM, Reprisal wrote:
Probably use net::http to grab the page, and use the response codes to fail gracefully. Otherwise test for a valid response using curl before calling open?
On Oct 22, 2006, at 11:00 AM, Brett Terpstra wrote:
Hi everybody.
As some of you may have figured out, I work a lot in HTML and CSS and I have a fetish for descriptive titles on links. I've been rewriting the wrap selection as link command and have it all worked out to grab the title of the link in the clipboard if it starts with http(s). I can't get it to validate the link, though.
Here's the text of the command:
#!/usr/bin/env ruby require "#{ENV['TM_SUPPORT_PATH']}/lib/progress.rb" require 'open-uri' link = "http://site.com" title = #{ENV['TM_SELECTED_TEXT']} s = IO.popen('pbpaste', 'r+').read if s.match(/(http(s?)://)/) then TextMate.call_with_progress(:title => "Opening Link", :message => "Retrieving Title for #{s}") do begin fp = open(s) title = fp.read.match(/<title>([^<>]*)</title>/i).to_a [1].strip link = s rescue title = "site unreachable" end end end print %{<a href="${1:#{link}}" title="${2:#{title}}" > $TM_SELECTED_TEXT</a>}
I've tried all kinds of overly complex methods that all yield the same results when the link is bogus:
/usr/lib/ruby/1.8/timeout.rb:42:in /bin/bash: -c: line 1: unexpected EOF while looking for matching `'' /bin/bash: -c: line 3: syntax error: unexpected end of fileconnect' from /usr/lib/ruby/1.8/net/protocol.rb:64:in /bin/bash: -c: line 1: unexpected EOF while looking for matching `'' /bin/bash: -c: line 3: syntax error: unexpected end of fileopen' from /usr/lib/ruby/1.8/net/http.rb:430:in /bin/bash: -c: line 1: unexpected EOF while looking for matching `'' /bin/bash: -c: line 3: syntax error: unexpected end of filestart' from /usr/lib/ruby/1.8/net/http.rb:324:in /bin/bash: -c: line 1: unexpected EOF while looking for matching `'' /bin/bash: -c: line 3: syntax error: unexpected end of fileproxy_open' from /usr/lib/ruby/1.8/open-uri.rb:525:in /bin/bash: -c: line 1: unexpected EOF while looking for matching `'' /bin/bash: -c: line 5: syntax error: unexpected end of filepopen' from /Users/brett/Library/Application Support/TextMate/Support/ lib/progress.rb:11:in This is what I get (and should get, I think) when I run it from a Ruby dialog:
<a href="${1:http://site.com}" title="${2:site unreachable}" > $TM_SELECTED_TEXT</a>
It works great when the site in the clipboard is valid. Any suggestions would be appreciated.
Thanks, Brett
Brett Terpstra : Art Director Circle Six Design, Inc. 111 Riverfront Dr, Suite 204
__ For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
_ For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
I posted an updated (and much more functional than my previous) version of the command this email refers to, did you see the most recent version?
Just a note: I'd leave out the "target" attribute if you distribute the snippet, it invalidates pages coded in HTML Strict or XHTML 1.1... [1]
Brett
[1]http://www.w3.org/MarkUp/2004/xhtml-faq#target
On Nov 12, 2006, at 6:46 PM, Jasper van der Meulen wrote:
The version from textmate itself was just i little bit too basic. Here's my simplified version...
<a href="${1:` # if the clipboard contains a single line, let’s use that export __CF_USER_TEXT_ENCODING=$UID:0x8000100:0x8000100 if [[ $(pbpaste|wc -l) -eq 0 ]] then pbpaste|perl -pe 's/&(?!([a-zA-Z0-9]+|#[0-9]+|#x[0-9a-fA- F]+);)/&/g' else echo http://site.com/ fi `}" ${2:target="${3:_blank}"} ${4:title="${5:$ {TM_SELECTED_TEXT:Link text...}}"}>${6:${TM_SELECTED_TEXT:Link text...}}</a>$0
For sure their can be made some changes .. so i'll listen carefully :-)