jimeh/manservant — pull request #8 by spartango (2012-05-04 06:00:47+00:00)
Title: Simple CLI tool

So I've implemented a static, single page generator for manservant pages. Yes it's more than a little hacky, but it does work and doesn't mess anything up.

The code is concentrated in open_manservant_page.rb, under lib/manservant.

The only change made to any of the other stuff was a reordering of the man-* divs in lib/manservant/server/views/page.erb, as this is actually a bug: Section listings can be generated as part of the to_html call, so this call ought to go first.

Here's how the static page generator works:

* Borrowing the helpers from the server, the page generator first parses the commandline arguments to figure out what page + section it needs.
* The generator then finds the appropriate man page and builds a ManPage object, again identical to the server code.
* Next, the generator assembles a template suitable for ERB from the layout.erb, page.erb, and public/*.css files. Where normally sinatra is responsible for composing the views, I compose them manually into a single template. The CSS is inlined into the doc head so that we can get everything in one HTML file.
* The generator then feeds the template and page object into ERB to render the final HTML.
* The HTML is written next out into a file in /tmp. Note that we can change this if we actually want to cache the pages.
* Finally, Launchy is invoked to open a browser. The script waits a few seconds to allow the page to render before deleting the file for cleanliness purposes. Again, this should change if we want to cache.

Thoughts? Sorry for any hacks or kludges...