Haml: Why You Should Use It
HAML 2.0 is out. I've been using HAML since back when I made my Assassins Game Hosting Service in 2007. If you are still using ERB or some other templating language for your web applications here is why you should given HAML a try.
HAML gets rid of end tags. By using Python like indentation it removes the need for you to type all of those pesky HTML endtags. Also, it lets you quickly see the nesting of tabs simply by the indentation of the line you are on. This quick look at nesting is espcially helpful when your HTML files start to get longer than 80 lines or so.
HAML generates pretty source. I am anal about how my HTML souce looks. I want it to be indented with spaces at every nesting point. If you've ever seen the HTML source for a webpage generated in on of the terrible, horrible WYSIWYG editors, you know exactly what I don't want. Every time I look at the source of pages generated by those tools a little piece of me dies. HAML is the complete opposite of this. It generates the cleanest possible HTML document it can. The file format convinces you to write cleanly, but it also smooths over some errors you could make. For instance, if you include unnecessary newlines in your source file, HAML removes them, leaving on the effectful newlines.
HAML is integrated with Ruby. ERB's Ruby integration is a joke. All it does it execute Ruby between <% %> with a little extra handling for loops and if statements. HAML's Ruby integration is like a Red Corvette. You can use = for ruby code with output, or == for ruby strings, or - for Ruby code without output. Also, now with HAML 2.0 error handling for Ruby and HAML is great a well.
HAML installation is easy. You can try HAML out right away with little effort, and no conflict with your current Rails installs just do the following:
gem install haml --no-ri
haml --rails path/to/app
I should also mention that HAML is used in my favorite static HTML generator, Staticmatic.
Questions or feedback? Email firstname.lastname@example.org.