How to use Yard for offline documentation

Posted on

I like being able to work offline, there is something quite reassuring about being able to sit on a train and still get on with my daily tasks without being dependent on a solid internet connection.

When working, a good part of my day is reading ruby gem documentation, so having that available offline is super helpful.

A tool I've recently started using to make this easier is Yard. Yard is pretty magical, but pretty much it looks at the code & comments of your local gems, then serves them in a nice bowser based UI. If you've ever used rubydoc.info it's what powers it behind the scenes.

Yard is really fun to get setup locally!

Getting setup

To get started, you need to install the yard gem.

gem install yard

You may also need to generate the Rdoc files, you can do this by running:

gem rdoc --all

Next you can turn on the yard server by running:

yard server --gems

This will output a URL where you can read all the documentation for the gems you have installed locally, awesome!

Using it with puma-dev

Having to turn on the yard server every time you want to lookup some information is a little tedious, so I setup a project on GitHub you can setup locally.

It uses puma-dev so it'll turn on the yard server & serve you the documentation when you visit http://yard-docs.test/ on your local machine.

This was written by Mike Rogers, a freelance Ruby on Rails developer based in London.

Share the ♥ by sharing this!

If you want to discuss this post, feel free to tweet me (@MikeRogers0) or drop me an email. Any code samples unless stated otherwise are licensed under the The MIT License (MIT). Spotted a mistake? Send me a pull request :)