Haml was originally introduced by Hampton Catlin with its initial release in 2006 and his work was taken up by a few other people.3 His motive was to make HTML simpler, cleaner, and easier to use. Since 2006, it has been revised several times, and newer versions have been released. Until 2012, Natalie Weizenbaum was the primary maintainer of Haml, followed by Norman Clarke until 2015.4 Natalie worked on making Haml usable in Ruby applications, while the branding and design were done by Nick Walsh.5
Version 2.2.0 was released in July 2009 with support for Ruby 1.9 and Rails 2.0 or above.6 Version 3.0.0 was released in May 2010, adding support for Rails 3 and some performance improvements. The fourth major version broke compatibility with previous versions, only supporting Rails 3 and Ruby 1.8.7 or above, and marked the switch to semantic versioning. Several amendments like increasing the performance, fixing a few warnings, compatibility with latest versions of Rails, fixes in the documentation, and many more were made in the Haml 4 series.7 Version 5.0.0 was released in April 2017. It supports Ruby 2.0.0 or above and drops compatibility with Rails 3.8 A 'trace'9 option, which helps users to perform tracing on Haml template, has been added.
Haml markup is similar to CSS in syntax. For example, Haml has the same dot . representation for classes as CSS does.
The following are equivalent as HAML recognises CSS selectors:
These render to the following HTML code:
Haml can be integrated into Ruby on Rails as a plugin. Similar to eRuby, Haml also can access local variables (declared within same file in Ruby code). This example uses a sample Ruby controller file.10
This renders to:
Haml is also capable of being used independently as a Ruby library.
Output:
Haml::Engine is a Haml class.
Haml uses whitespace indentation (two spaces) for tag nesting and scope, replacing open-end tag pairs. The following example compares the syntaxes of Haml and eRuby (Embedded Ruby), alongside the HTML output.
Key differences are:
The above Haml would produce this XHTML:
The official implementation of Haml has been built for Ruby with plugins for Ruby on Rails and Merb, but the Ruby implementation also functions independently. Haml can be easily used along with other languages. Below is a list of languages in which Haml has implementations:
"Encoding". Retrieved 29 January 2016. http://haml.info/docs/yardoc/file.REFERENCE.html ↩
"UTF encodings". GitHub. Retrieved 7 February 2016. https://github.com/haml/haml/blob/88110b0607efca433c13bb1e339dcb1131edf010/lib/haml/util.rb ↩
"About". Retrieved 28 April 2018. http://haml.info/about.html ↩
"Changelog". GitHub. Retrieved 28 April 2018. https://github.com/haml/haml/blob/master/CHANGELOG.md ↩
"Trace Option in Haml". Retrieved 16 February 2016. http://www.rubydoc.info/github/haml/haml/Haml/Options:trace ↩
"Using Haml". Retrieved 7 February 2016. http://haml.info/docs/yardoc/file.REFERENCE.html#using_haml ↩