Exposure to Haml
Published: July 25th, 2007HAML is markup haiku, don’t believe me? The proof is in this post, may you never turn back to regular HTML!
I really love Haml.
In fact, I really, absolutely, admittedly, undoubtedly, beyond a doubt, in actuality, love Haml. Does that sound obsessive to you? It should, because that will tell you how much I adore Haml. I’d probably sleep with haml over Angelina Jolie, given the chance anyway.
Haml is poetry, it’s “markup haiku”.
Need proof? Okay, look how sexy this is, coming from a Rails application.
!!! %html %head %title= "Film Fest :: "+controller.controller_name.capitalize = stylesheet_link_tag 'screen' = javascript_include_tag 'ufo' %body #container #banner %h1 Podcast Film Festival #left %h2 Menu %ul - if logged_in? %li= link_to "My Account", edit_user_url(current_user) %li= link_to "Films", categories_url %li= link_to "Messages", view_messages_for_user_url({:user_id => "#{current_user.id}"}) %li= link_to "My Blog", view_blog_for_user_url({:user_id => "#{current_user.id}"}) %li= link_to "Log out", logout_url %li Invite Friends %li= link_to "Users", users_url - unless logged_in? %li = link_to "Log In", new_session_url - if is_admin? %h3 Logged in as an admin %p administration privileges granted %li= link_to "Pages", pages_url %li= link_to "Approve Assets", assets_url #content = yield - unless flash[:notice].blank? #flash = flash[:notice] #footer %h1 In sexy code we trust
Does that not look sexy to you? I mean, c’mon 36 lines of code for a complete layout page? Auto closing tags? Auto closing conditionals? The absolute simplicity of the code? For more readability you can split the lines up a bit, but I personally like to compact everything.
To call an id of a div you simply just do #(id_name), woah, it’s like I’m extracting it from css. I love it!
To call a class of a div you simply just do .(class_name), woah x2, it’s like I’m extracting it from css. I freaking love it!
%tags automatically close on themselves, providing valid code. Did I say woah already? How about miraculous! I adore it!
Did I mention it’s 16x faster than markaby? Rock on!
HAML provides you with an proper structure of your elements, why? Because of the way you indent, you’re forced to code properly. There are just so many great things, I’m so ecstatic that I can’t type my ideas properly. It’s also changed a lot of ways that I code, for e.g back in the day I used to have a lot of Ruby in my rhtml, well you’re usually supposed to put those in a helper. Well thanks to Haml is practically forces you to, you’ll know why when you start to use it. It’s definitely a similar feeling from using basic rails testing, then going to rspec/bdd.
Seriously just give it a shot, see how good it feels to instantly have your lines of code be reduced more than fifty percent, just on the first try.
For more documentation and information, take a look at the Haml website.


OMFG! This is the SHIT. I hardly ever stop and make comments as a i browse daily but this blurb froze me.
I’m very new to ruby & rails but after reading this is motivation for me to get back to my books. (I’ve been slacking lately). The fact that you can call DIVS with that easily, as well as controller methods, and it looks so got damn clean!
Dude, this the kick in the ass I needed. I’m gonna be hittin your blog up, keep dropping knowledge like this and I’ll be a loyal visitor.
Thanks for the heads up.
No excuse me while I add this to my del.icio.us as HAML IS THE SHIT.
Yeah, it looks nice and I like the idea of properly indented HTML output. The one thing that looks like an eyesore might be a mistake in your post: the => encoding for the => in your hash. I wouldn’t think HAML requires that kind of ugly syntax.
Fatts, I love the enthusiasm. Thanks for loving HAML so much. Maybe I will post more code examples over the next couple days for people to get up to speed, and any questions that I ran into myself.
Bill, thanks for pointing that out. I took care of that. Wordpress and it’s damn character encoding… ha.
Daniel,
Sounds good. I’ve got you bookmarked so when ever you get some time, please do post more. I’ll be looking forward to more examples. Especially in Real-world situations.
As a young developer, this is the type of progress I look forward too. I’m sure there are others like myself that get intimidated a bit by heavy markup. It seems to dull out the creative side that needs (especially coming from a design background). I chose Ruby as my first language for its simplicty and this is a testament why.
Feed me more!
Fatts, I’m a young developer myself. I know exactly what you’re talking about, because that is what I was looking for myself. I found it, and I’m learning a lot. I’ll definitely share my progress with you. I also come more from design than programming, that’s why I chose Ruby myself. Not so much for it’s simplicity, because it’s hardly simple; more so because of how beautiful the code looks under Textmate! Ha!
You do that,
post some more haml examples please.
I am almost done with a simple blog app in haml and rails with ruby code syntax.
it is fast, low memory and perfect for ruby bloggers. ;)
i will put it github soon.
;)
Ready. Set. Go.
In terms of the formatting, you're allowed to use markdown, textile, or basic html; it's truly up to you -- what strikes your fancy?
You don't have to worry about your e-mail address being sold to a russian-spam-mafia. I'm only going to use it for my own weird needs; like asking you out for a date on a lonely night of coding.