This revision is from 2012/05/10 15:31. You can Restore it.
Haml is a simple lib for generating XHTML/XML without specifying needless parts.
It can be intimidating at first glance, because it seems so unlike the HTMLish stuff you're used to. Let's prove its superiority one feature at a time (this is a shortened version of http://haml-lang.com/tutorial.html ).
-
%atag{a: b}
is better than<atag>…</atag>
-
%atag.aclass
is better than%atag{class: "aclass"}
-
%atag#an_id
is better than%atag{id: "an_id"}
-
#div_id
is better than%div#div_id
-
= 3*2
is better than {[<%= 3*2 %>}}
So, to put them together, compare the Erb of:
<div id="banner" class="shadowed" lang="en"><%= item.title %></div>
…versus the Haml of:
#banner.shadowed{lang: 'en'}= item.title
∎
BTW(Edit)
:markdown
Note(Edit)
These can be quickly tested in `pry` (which is
gem install pry{,-doc}then
run `pry` from the shell - it's a better `irb`) with:
pry -rhaml
Haml::Engine.new('#testtest').render
…and, of course, if you find yourself doing this often, you could add
something like this to your ~/.pryrc —
def hammit haml
require 'haml'
Haml::Engine.new(haml).render
end
…then it's as simple as:
echo 'hammit %q{#testtest}' | pry