« rendering html from irb | Main | More on BSB's »

rendering html in firefox from irb

Here's a Firefox version of yesterday's script to render html from irb.

For best results, go to about:config and set browser.link.open_external to 1 (or from the menu, go to tools->options->tab, and set "open links from other applications in:" to "the most recent tab/window")

here's the script:

require 'base64' 
class Firefox

 #edit to suit
 @@firefox_path='C:\Program Files\Mozilla Firefox\firefox.exe'

 def Firefox.html_as_data_uri(html)
      'data:text/html;base64,'+ Base64.encode64(html).gsub("\n", '')
 end

 def Firefox.show_html(html)
  #can't use fork on windows
  IO.popen("#{@@firefox_path} #{Firefox.html_as_data_uri(html)}")
 end
 
end