Read me then sing me

Leave a comment

February 20, 2013 by Rob Nichols

Sinatra is a lovely light weight alternative to rails, and today I have used it to create my simplest web app to date.

The problem
I have never been quite sure what my README.rdoc file will look like until I’ve posted it on github. Using rdoc markup ensures that the README is rendered nicely in github, but getting anchors and indentation to play nicely can be a bit of a fag.

You can generate an html version of the README.rdoc by entering this at the app root:

rdoc README.rdoc

But if you look at all the gubbins that is created along with the html file, it is evident that this is over the top. If nothing else, it creates a load of files you’ll need to git ignore, or delete after you’ve used them.

The solution
Fortunately, the rdocs documentation offered a simpler solution. RDoc::Markup::ToHtml will convert rdoc markup to HTML. That gave me an HTML output, but how do I display it?

Sinatra to the rescue. I’ve posted my code here. I think the code speaks for itself.

To use it, just copy display_readme.rb to your app root, and

ruby display_readme.rb

Then point your browser at http://localhost:4567 and your README.rdoc will be displayed in HTML.

It really is that easy, and that really is a web app in 10 lines of code!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: