Viewing RI in a web browser with lighttpd

In his post Matthias Georgi showed how to view RI in a web browser. He’s using Apache, so I rolled out a couple of snippets for lighttpd users.

First I added a host to my /etc/hosts:

127.0.0.1     ri

And created a virtual host in my lighttpd.conf

$HTTP["host"] =~ "ri" {
	server.document-root = "/my/projects/path/ri/"
	cgi.assign = ( ".rb" => "/usr/bin/ruby" )
	url.rewrite-once = (
		"^(.*)$" => "ri.rb?$0"
	)
}

Since lighttpd has a diffrent way of handling mod_cgi request parameters Matthias’es script needed a little adjusting:

#!/usr/bin/env ruby

require 'rdoc/ri/ri_driver'
require 'rubygems'

print "Content-type: text/html\r\n\r\n"

ARGV << ENV["QUERY_STRING"].sub("/", "") << '-f' << 'html' <<

ri = RiDriver.new

print '<html><body style="width:600px; margin:auto; padding:20px"><pre>'
ri.process_args
print '</body></html>'

Restart your lighttpd, browse to http://ri/String.capitalize. That’s it!