convert haml to erb

1,520 views
Skip to first unread message

Greg Weber

unread,
Oct 16, 2008, 10:11:14 PM10/16/08
to Haml
it may sound contradictory, but I am looking for a tool to convert
haml to erb in order to use haml. If one's team is not using Haml,
one can convert to haml, edit the file, and then convert back to erb.
Also, one of the objections to Haml is that it will be more difficult
for designers to work with. This would be solved by converting the
Haml to erb to be worked on, and then back to Haml.

Does such a tool exist? Is it possible to hack the Haml source to
produce one?

Thanks,
Greg

Nathan Weizenbaum

unread,
Oct 16, 2008, 10:23:51 PM10/16/08
to ha...@googlegroups.com
No, no such tool exists. In fact, it's not possible to make without
parsing Ruby code - Haml supports several constructs, such as = with a
block and comments within Ruby code, that ERB doesn't. It might be
possible to modify the Haml engine to convert a fairly large subset of
Haml to ERB, but it would take considerable work to even get to an
imperfect implementation.

I'd suggest trying to convince your team to give Haml a try in its own
right. Designers often take to it even more than developers, because of
the similarities to CSS and how closely it matches the document tree.

Mislav Marohnić

unread,
Oct 17, 2008, 3:46:26 AM10/17/08
to ha...@googlegroups.com
On Fri, Oct 17, 2008 at 04:23, Nathan Weizenbaum <nex...@gmail.com> wrote:

It might be
possible to modify the Haml engine to convert a fairly large subset of
Haml to ERB, but it would take considerable work to even get to an
imperfect implementation.

Here's an imperfect implementation without much work: http://gist.github.com/17371

But yeah, it probably sux for various cases. It doesn't even do the indentation right in blocks.

Greg: you may succeed to produce a haml2erb tool, but going bidirectional ... I don't think it will ever work. If you have only a slightest imperfection in html2haml and haml2erb tools (and just now we saw they had), your templates will finish up broken.

Greg Weber

unread,
Oct 18, 2008, 10:19:42 PM10/18/08
to Haml
Thanks, I figured something like the gist was possible. Bad spacing
is unimportant, I think. There are plenty of html pretty printers out
there, including possibly the one in HAML that could fix that. I
wonder if avoiding using the constructs in HAML that cannot be used in
ERB would solve most of the problems.

But I will heed your warnings though and not attempt a real version.

On Oct 17, 2:46 am, "Mislav Marohnić" <mislav.maroh...@gmail.com>
wrote:

Daniel Choi

unread,
Apr 14, 2013, 8:28:53 AM4/14/13
to ha...@googlegroups.com, webs...@gmail.com

I recently wrote such a tool. Sorry it arrives 5 years after you asked about one.

https://github.com/danchoi/herbalizer
Reply all
Reply to author
Forward
0 new messages