The land of Shattered dreams

Welcome to the online revolution…

Trying Haml, Coffeescript, Ruby and Sinatra

| Comments

I am looking at ways that I can build a web front-end for a system I am going to develop at work. Basically, I want to have a number of web services that will provide the data and then write a front end in html and java script to consume these services and display the data to a user.

I’m not a javascript expert, can do a bit of html and really didn’t want to do use java as it isn’t the quickest thing develop a prototype.

In the end I chose Sinatra, a DSL for quickly creating web applications in Ruby with minimal effort. It is stupidly easy to create a web application! For example:

1
2
3
4
require 'sinatra'

get '/hi' do
    "Hello World!"

Will return “Hello World!” when you go to http://localhost:4567/hi. I used the ROXML gem to squirt out an xml representation of a ruby object and I had a web service in around 30 lines of ruby.

So I had my web service up and running. Now to consume it… As I’ve mentioned before, I like bootstrap as it is really easy to write a good looking interface without having to know loads of CSS. HTML is ok, but it can look a bit of a mess, so I decided to use Haml. It gets transformed into html, but it makes your markup look beautiful. Using it you have to go out of your way to write nasty html. Indentation is significant (a la python) so you have to right it neatly!

The final piece of the jigsaw is coffeescript, a little language that compile into javascript. The aim of coffeescript is to expose the good bits of javascript in a simple way. I like it because it removes the need for endless curly brackets and the function keyword.

All in all, I’m pretty pleased with the results. None of it is earth shattering, but the progress bars are pretty neat and I like the way I’ve built the results table.

If you want to see the code, you can clone it using git 

1
git clone https://bitbucket.org/typingincolor/ajax-prototype.git

Comments