intellidiot
intellidiot

Reputation: 11228

Convert Haml to HTML without evaluating inline Ruby script

I need to convert Haml scripts to their equivalent HTML scripts. As I'm doing this outside and without running the main rails project, the Ruby scripts present in the Haml files are throwing exceptions (which is obvious). Now, I won't mind if the Ruby script is present in the output HTML (in that case it'll look like an erb, that's fine for me). I'm concerned with some html tags only.

It seems like if I can override Haml::Engine#render(scope = Object.new, locals = {}, &block) method then it could help. But not getting it fully.

Any idea?

Update

Converting only - foo and = foo blocks into Erb <% foo %> and <%= foo %> (respectively) won't work completely, because interpolation will be there, like:

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

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

Other than those interpolations this works well for - and =.

Upvotes: 4

Views: 2226

Answers (1)

Zach Inglis
Zach Inglis

Reputation: 1257

Have you looked into the HAML to ERB converter gem?

Upvotes: 2

Related Questions