5. What’s Changed?
All <arrowheads> are gone
Tags and code both self-close by indentation
id=”xyz” and class=”abc” are just #xyz and .abc
<div> is the default tag - for others, use %tag
<%= some code %> is now just = some code
Same for <% some code -%>, use - some code
6. Visual Simplicity
The RHTML version has 261 lexical tokens
counting each word in strings and syntactic white-space
The HAML version has 117 tokens
That makes it easier on the eyes and the fingers!
Markup Haiku
8. Extra benefits
Need care to close tags correctly in RHTML
In HAML, generated code is indented properly
including after nesting layouts and partials!
valid XHTML with no extra effort
DIVs almost always get a class or an ID or both
Plays well with RHTML during conversion
9. Other niceties
Attribute values are Ruby code:
%label{:for=>@field.name}= @field.description+’:’
Ruby blocks are automatically closed:
%table
- @people.each do |person|
%tr
%td= person.name
%p.footer
You can declare multiple classes, etc:
%td.person.alignleft#husband= @husband.name
10. Other niceties... 2
ID and class attributes can come from an object:
%div[@mother]
uses @mother.class and @mother.id to become:
<div class=”person” id=”person_5724”>
Most self-closing tags are recognised
others may be declared self-closed: %br/
Comments start with a single / and are output!
Even multi-line; a comment wraps indented content
11. Other niceties... 3
Automatic generation of DOCTYPE tags:
!!! and !!! XML become
<?xml version=quot;1.0quot; encoding=quot;utf-8quot; ?>
<!DOCTYPE html PUBLIC quot;-//W3C//DTD XHTML 1.0 Transitional//ENquot;
quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtdquot;>
Continue a long line using a trailing |
:filter passes the content to the filter:
%p
:markdown
Textile
=======
Hello, *World*
12. Tools
Syntax highlighting modules available
JEdit, Eclipse + RadRails, TextMate, (G)Vim, Komodo, Emacs
or simple VIM setup (in your ~/.vimrc):
au BufRead,BufNewFile *.haml set sw=2 sts=2 et
13. How to install
./script/plugin install
http://svn.hamptoncatlin.com/haml/tags/stable
Also available as a GEM for use outside Rails
Website: http://haml.hamptoncatlin.com/
See also SASS - similar approach for stylesheets
Developer discussion: http://groups.google.com/group/haml
Thanks to Hampton Catlin and his contributors!