Haml is a markup language that’s used to cleanly and simply describe the HTML of any web document without the use of inline code. Haml functions as a replacement for inline page templating systems such as PHP, ASP, and ERB, the templating language used in most Ruby on Rails applications. However, Haml avoids the need for explicitly coding HTML into the template, because it itself is a description of the HTML, with some code to generate dynamic content.
Haml’s development as a language is based on adherence to several core principles. These are:
Markup Should be Beautiful
Markup should not be used merely as a tool to get browsers to render a page how the author wants it rendered. The rendering isn’t the only thing people have to see; they have to see, modify, and understand the markup as well. Thus, the markup should be just as user-friendly and pleasant as the rendered result.
Markup Should be DRY
HTML involves major repetition. Every element is named twice: once before its content and once after. ERB adds even more repetition and unnecessary characters. HAML avoids all of this by relying on indentation, not text, to determine where elements and blocks of code begin and end. Not only does this result in smaller templates, it makes the code much cleaner to look at.
Markup Should be Well-Indented
One of the major problems with ERB is that not only does it not encourage well-indented code, it actively makes it challenging, or even impossible, to write. This leads to confusing, unreadable HTML, when it should be well indented and reflecting the underlying structure of the document. Haml automatically properly formats all tags to that it does.
HTML Structure Should be Clear
XML and HTML are formats built upon the idea of a structured document. That structure is reflected in their markup, and it should likewise be reflected in meta-markup such as Haml. Because Haml’s logic is based on indentation of child elements, this structure is naturally preserved, making the document much easier and more logical for mere humans to read.
Haml was created because Hampton got really annoyed having to keep hand-typing out templates. So many advances have been made in web-development, but the template has remained the same. Time for something new.
Based on those frustrations, Haml was born as an experiment. However, Haml quickly proved itself in several production-level websites created at Unspace Interactive. In fact, the entire company’s development team quickly shrugged off ERB completely and have gone entirely to Haml based development.
Haml quickly proved itself to be a productivity boon. Also, designers love Haml for its similarities to CSS. Things are better in web development land since Haml arrived.
The Haml Team
Haml was created by Hampton Catlin, the author of the original implementation. However, Hampton doesn’t even know his way around the code anymore and now just occasionally consults on the language issues.
Natalie Weizenbaum was for many years the primary developer and architect of the “modern” Ruby implementation of Haml. Her hard work endlessly answering forum posts, fixing bugs, refactoring, finding speed improvements, writing documentation, and implementing new features is what has kept the project alive.
Norman Clarke, the author of Haml Spec and the Haml implementation in Lua, took over as maintainer in April 2012.
Haml’s branding and design were contributed by Nick Walsh.
The Haml implementation is available under the MIT License.