Posts [ 19 ]

Topic: Haml -- A Great Alternative to RHTML

Is your head is swimming and your eyes blurring from <%= and %> tags? Are you having trouble picking out your document structure among all the markup? Lucky for us, Rails allows for alternate template languages. One that is gaining traction right now is Haml. The reason is that it generates beautiful XHTML every time and your source reflects your document structure.

This all seems good, but what's the catch? Well the answer is pretty much: There is no catch. But, it's a work-style change. First let's look at what an RHTML file and its corresponding Haml file might look like:

If you're like me, you will find the Haml much more concise, and reflective of the structure of the XHTML document. Coincidentally, that makes it easier to associate CSS styles with elements without doing a ton of visual parsing of your code. In Haml's trunk (if you like to live on the edge) is Sass, which is to CSS as Haml is to Rhtml. Sass is best left for a different tutorial.

Re: Haml -- A Great Alternative to RHTML

but it used to have a problem with a trailing <p> after the form tag. It wasn't a problem that affected the function, but the output HTML is otherwise so perfect, everyone screamed. It has since, I believe, been fixed as a special case.

The reason for the inconsistency is that the form_for helper concats directly onto the Erb stream and is written with that run-in formatting.

Notice no whitespace or newlines.. That's because if you fit some images to a <div> with a specific width (to fit exactly) Explorer tends put a space between the div and the first image breaking your layout..

Re: Haml -- A Great Alternative to RHTML

Is this a pervasive issue or only for some table-based IE layouts. If the latter, then a simple helper will give you exactly what you want. One thing Haml is big on is yanking stuff out into helpers and partials. Dunno if this is a good answer for you. I recommend you post a q on the Haml Google group. They're extremely helpful and quick to respond.

Re: Haml -- A Great Alternative to RHTML

Not a big fan of the syntax either. Hobo with DRYML is really outstanding; perhaps that might make folks looking at this as an alternative a little happier. Also, cwd, thanks for this and please feel free to add to the Hobo information. I know Tom over at HoboCentral is struggling getting documentation and such out and it would be great to see more folks involved in terms of bolstering the efforts to get folks trained up.