Offline Gem Server RDocs

Twitter _ Jesse Newland_ sinatra-rubygems + Passeng ....jpg

Get Sinatra, Rubygems, and Passenger working for offline RDocs? Count me in. I saw this and new I had to have it. I’ve been on some long plane rides recently and I frequently find myself wanting to look up something from a gem’s documentation while I’m coding. You can use the gem server command but that’s just such a pain to do every time you want to look something up. I hadn’t really given it much thought that there might be an easier way until I saw Jesse’s tweet about it. Having this offline using passenger at http://gems.local is great but I wanted to have a little more searching baked in. Here’s how I did it:

  1. Install the hanna gem from mislav.

    You may need to have the HAML gem installed for this to work. The hanna gem is a great theme for rdoc output. It includes javascript to make some ajaxy type search so you can filter methods by typing in to a text field in one of the frames on the left. It took me a little while to find this theme. It’s the one currently in use on GitRDoc, which is a great resource (if you’re online).

  2. Tell rdoc to use the hanna theme

    In order to tell rdoc and gem to use this when you use the "gem" command, you need to add to your .gemrc. Beware that this will affect all future rdoc generation when you install a gem. Add the following to ~/.gemrc:

  3. Regenerate your rdocs

    You then need to regenerate all of your rdocs with this theme. You can do this by executing the following:

  4. Get sinatra-rubygems

    Clone my fork of Jesse Newland’s sinatra-rubygems from GitHub:

    git clone git://github.com/jseifer/sinatra-rubygems.git

  5. Add it to Passenger

    Hook it up to your passenger preference pane and set the name to "gems.local", restart Apache and you’ll be all set:

    passenger pref pane.jpg

After you complete the above steps, everything should be working. Enjoy! This will come in handy next time you don’t have internet access and need to look up some methods. I’d like to give a special thanks to Jesse Newland for releasing the sinatra-rubygems app.

Update: k776 points out in the comments that this doesn’t work on the latest version of rdoc, which is 2.4.1 as of this writing. It seems 2.3.0 is the version to go with.