bloc referral

If you are interested in learning to code with a mentor, try bloc and get $100 off.

Friday, January 30, 2015

Marked HAML

I spent quite some time in my developing learning avoiding HAML, SLIM, and all other template alternatives, but recently I took on the task of working on a project that was exclusively written in HAML.

HAML is a template language that is meant to make writing html less of a drag. It was very common for myself to forget closing brackets and div tags which always annoyed me greatly, but I avoided the simplicity of HAML because I wanted to force myself out of that bad habit. HAML does not require any brackets and works with spacing and indentation to convert the valid html.

I initially reaction when started the project was to convert the existing HAML into/erb right away, but I then read an article from Hashrocket and found they used HAML exclusively and it got me thinking, maybe it's time for start learning this.

Here is an example of html converted to haml:

What annoyed me the most was the errors received due to the sensitivity of spacing. If your indentation is off HAML will tell you. If you write invalid code, HAML will tell you and there is less flexibility with how much Ruby logic you can place in your template.

Learning Ruby/Rails first introduced me to erb and I love it and understand it, which is another reason why I avoided HAML.

I have since stopped work on this project but did walk away with some more experience in this templating language. I can't say I would go for HAML at the start of a project but I don't think I need to avoid it anymore. I will definitely give it another shot on one for my smaller projects, especially since I am pretty sure this is not the last I will see of it.

If you come across HAML somewhere I recommend learning it and use tools like hamle2erb or htmltohaml

No comments:

Post a Comment