Archive for January 4, 2012
-
Writing elegant HTML with HAML
January 4, 2012
This post was originally published in the Rambling Labs Blog on January 4, 2012.
Another cool thing that we learned while building the new Rambling Labs site was HAML. It’s a markup language that is based on the premise that ‘Markup should be beautiful’, in their own words.
It’s very easy to install, just add
gem 'haml'to yourGemfileand runbundle install. To use it, replace yourview_name.html.erbfile with aview_name.html.hamlfile.Like SASS and CoffeeScript, to achieve the beauty it professes, HAML uses indentation to determine what it should do next. This means, and you guessed it, that it writes beautifully.
Compare this ERb file:
<div id="single_post"> <h2 class="post_title"><%= link_to post.title, post %></h2> <div