require "ev/ruby" require "ev/net" begin require "win32ole" require "win32/registry" rescue LoadError $".push "win32ole.so" $".push "win32/registry.rb" end def windowsbrowser $stderr.puts "Looking for default browser..." filetype = "htmlfile" application = nil begin Win32::Registry::HKEY_CLASSES_ROOT.open('.html') do |reg| filetype = reg[""] end Win32::Registry::HKEY_CLASSES_ROOT.open(filetype + '\shell\open\command') do |reg| application = reg[""] end rescue NameError $stderr.puts "Only available for Windows." end application end def linuxbrowser application = "" application = `which galeon 2> /dev/null`.chomp if application.empty? application = `which mozilla 2> /dev/null`.chomp if application.empty? application = `which firefox 2> /dev/null`.chomp if application.empty? application = `which opera 2> /dev/null`.chomp if application.empty? application = `which konqueror 2> /dev/null`.chomp if application.empty? application = `which htmlview 2> /dev/null`.chomp if application.empty? application = nil if application.empty? application end def defaultbrowser res = nil res = windowsbrowser if windows? res = linuxbrowser if linux? res end def showinbrowser(html, browser=defaultbrowser) port, io = TCPServer.freeport(7701, 7709) unless browser.nil? Thread.new do begin #command = "1234 \"http://localhost:#{port}\"" if linux? #command = "L:/prog/MozillaFirefox/firefox.exe \"http://localhost:#{port}\"" if cygwin? #command = Win32::Registry::HKEY_CLASSES_ROOT.open('htmlfile\shell\open\command')[0] + " \"http://localhost:#{port}/\"" if windows? command = "#{browser} \"http://localhost:#{port}\"" Thread.pass system(command) rescue end end end HTTPServer.serve([port, io]) do |req, resp| resp << html resp.stop end end def tab2html(tab) res = "" tab = tab.to_html(false) res << "\n" res << "
\n" res << "%s | \n" % veld end res << "