Should I go from erb to haml?

When I first started learning Rails, erb seemed very natural to me because I used Smarty and other templates in the past, and even more, I was very busy programming Wordpress templates (where it all looks like erb a lot).

Now, after some time, I accidentally looked at haml and, at first sight, I am very impressed with the beauty and simplicity. I heard that, especially for older versions, haml is slower, but I feel that rendering the views will not really be a problem.

So, now I am seriously thinking about converting a rather large project that I am doing, from erb to haml. I am always looking for ways to write better code.

But what do you think? Is that a good idea?

+4
source share
3 answers

Haml is a great choice to launch a new project. But I see no reason in converting an existing project from ERB to Haml, especially if you have a large number of templates that require rewriting. Do not fix what is not broken.

+11
source

I agree that there is no real need to migrate, you can just mix and match them.

But ... I highly recommend you switch to haml effectively. I feel that the effort to convert erb to haml is not that great. In most cases, you will cut out the elements. The reward, on the other hand, is great.

Haml is much more compact and, most importantly, more readable. Since it is very structured, the attachment is much clearer, and this makes your views more comfortable.

I don’t know about yours, but we had erb templates that were completely unreadable, different developers have different styles, how do you deal with nesting inside erb? nested code? nested code inside elements? nested elements inside code? In haml there is no doubt about this. It's clear. Everything is cut out when you nest. And don’t need to untie, remembering to close </td> or </div> .

It also makes your files much smaller (easier to skip).

There is a really possible performance issue, but if it really bothers you, I would suggest looking slim , which is almost identical to haml, only blindingly fast.

+3
source

Haml is excellent and I recommend it for future templates. However, you do not need to change the existing erb code to haml, since you can freely mix erb and haml in the project. As submissions become cumbersome, you can think of rewriting, but there is no real need to change them all at once β€” it will take quite a while and could potentially lead to errors.

+1
source

Source: https://habr.com/ru/post/1338812/


All Articles