Start Spreadin’ the News

January 19th, 2009  |  Published in ruby

I’m sure I’m not the only male in America who, when Palin dropped her first wink, sat up a little straighter on the couch and said, ‘Hey, I think she just winked at me.’ And her smile. By the end, when she clearly knew she was doing well, it was so sparkling it was almost mesmerizing. It sent little starbursts through the screen and ricocheting around the living rooms of America.

— Rich Lowry of the National Review

Sinatra just made my day that way.

As much as I’ve been enjoying Rails for a few things, I’ve wanted something a little more lightweight for several others. I’ve waffled between doing them as Ruby CGIs running under lighttpd on my MacBook or finally breaking down and trying to learn WXRuby or something similar. Both options lack a certain portability, which is to say they have a requirements list more than one item long. I also just don’t feel like dealing with learning a GUI toolkit.

So Sinatra holds out the promise of being able to put things together without the weight of Rails and without having to learn much of a Whole New Something to get decent results.

Starting with the last version of my NetNewsWire attentional graphing script, I dropped this line:"/Users/mph/Sites/attention/index.html", 'w') {|f| f.write( }

and added this:

eruby = 

get '/' do



Running that and visiting http://localhost:4567/ gives me the same thing I was outputting as a static HTML file, only wrapped up in a live server and with the promise that it would be a simple matter to make something even more logic-ish.

I don’t know much about how it compares to Camping except that I was able to grok it instantly and it sent little starbursts through the screen, ricocheting around my living room.

There’s lots of neat stuff in there: Templating, routing, support for ERB, and other niceties wrapped up in a simple syntax. More to the point, a Sinatra app can live in a single file and ride around on a thumbdrive, ready to operate anywhere there’s Ruby and the ability to install the Sinatra gem.

Leave a Response

© Michael Hall, licensed under a Creative Commons Attribution-ShareAlike 3.0 United States license.