Haml has a feature called “Whitespace Preservation” which usually tries to nicely indent your markup. This is great.
However, sometimes it gets in your way – especially when it indents your <pre>
paragraphs wrong.
I had a setup like
%p Here, some code! = render_some_code
where #render_some_code
would return some markup.
def render_some_code "include 'cells'ninclude 'apotomo' /pre>" end[The missing < before /pre is intentional as it breaks this writing, haha.]
I expected the render output to be ...nice.
Here, some code! include 'cells' include 'apotomo'Nevertheless, it turned out to be even nicer. Haml's nice indentation striked.
Here, some code! include 'cells' include 'apotomo'I found this delicious post by Chrissy Eppstein and in turn read the haml docs on whitespace preservation.
Using
Haml::Helpers#find_and_preserve
, it works like a charm now. I don't know why, neither how, but it works.include Haml::Helpers def render_some_code find_and_preserve "include 'cells'ninclude 'apotomo' /pre>" end
I think that ‘~’ is what you are looking for.
Gist just incase the format does not come through in the comment http://gist.github.com/604030
%p
Here, some code!
~ render_some_code
LikeLike