Convert Haml to HTML without evaluating the embedded Ruby script

I need to convert Haml scripts to their equivalent HTML scripts. Since I am doing this outside and not starting the main rails project, the Ruby scripts present in the Haml files throw exceptions (which is obvious). Now I will not mind if the Ruby script is present in the HTML output (in this case it will look like erb, this is good for me). I'm only interested in those html tags.

It seems like if I can override the Haml::Engine#render(scope = Object.new, locals = {}, &block) method Haml::Engine#render(scope = Object.new, locals = {}, &block) , then this can help. But do not get it completely.

Any idea?

Update

Converting only - foo and = blocks foo to Erb <% foo %> and <%= foo %> (respectively) will not work completely, because there will be interpolation, for example:

%div{:class => "#{cycle("cssClass1", "cssClass2")} anotherCssClass"}

A valid output for my case could be: <div class=<%= "#{cycle("cssClass1", "cssClass2")} anotherCssClass" %> ></div>

Besides these interpolations, this works well for - and = .

+4
source share
1 answer

Have you looked in the HAML to ERB converter ?

+2
source

All Articles