[TxMt] Re: HTML output: Open link in default browser?

Stefan Daschek stefan at daschek.net
Sat Mar 1 12:50:17 UTC 2014


Thanks, I didn't know about |TextMate.system(...)| -- that's exactly 
what I was looking for. ?

It took a while until I got the escaping right, here's what I ended up with:

|def  link_to(title, local_path)
   url =URI.escape("file://#{local_path}")
   title =CGI.escape_html(title)
   %{<a onclick='TextMate.system("open#{Shellwords.escape(url)}"); return false;' href='#{url}'>#{title}</a>}
end
|

Gist with the complete setup: https://gist.github.com/noniq/9289157

Stefan

Am 01.03.14 07:15, schrieb Allan Odgaard:

> On 1 Mar 2014, at 9:20, Stefan Daschek wrote:
>
>     Is it possible to force specific links in the HTML output window
>     to open in the default browser [...] I have a Rails project where
>     the testsuite already creates a dump of the HTML page for each
>     failed feature spec. Now I'm trying to extend RSpec's
>     TextMateFormatter to include links to these files. Works so far,
>     but I need to open the saved HTML pages in my default browser so
>     that I have my usual developer tools around for debugging.
>
> Given that you are modifying the generated output, you can change the 
> link to use JavaScript and TextMate.system(), example:
>
> |<script>
> function open_url(url) {
>    TextMate.system("open '" + url + "'");
> }
> </script>
>
> <a href="#" onClick="open_url('http://macromates.com/'); return true;">Open Website</a>
> |
>
>
> _______________________________________________
> textmate mailing list
> textmate at lists.macromates.com
> http://lists.macromates.com/listinfo/textmate

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macromates.com/textmate/attachments/20140301/255b2c77/attachment.html>


More information about the textmate mailing list