On 8 feb, 15:32, "Nathan Weizenbaum" <
nex...@gmail.com> wrote:
> This is why we use the newline escapes: nested templates don't touch them at
> all. Note that your solution still falls down if you have a three-deep
> nested template.
I hadn't tested that so I'll take your word for it. I imagine I could
avoid that by echoing the markers through rather than suppressing
them; I probably should have done that anyway. Of course, even if it
works with any level of nesting it's still a hack.
I have another nascent idea that may work and which I like much better
than this hacky one I've shown so far. Basically if I can train
push_script to accept an Array parameter rather than a straight String
then it could act in a way that preserves whitespace when appropriate
and leaves it untouched otherwise through any number of nested
template levels.
Basically it would act as follows:
* if param is a String, act just like it does now
* if param is an Array, iterate and handle each item as it does now
* if param (or any item during iteration) is a special String
subclass, say PreservingString, suppress the tabulation and instead of
appending the result to the existing @buffer, start a new one marked
as preserving whitespace and stick the result in there (not sure yet
whether this should be a Haml::Buffer subclass or just a normal
instance with an attribute set)
* this would be accompanied by a helper method that instantiates one
of these PreservingString instances
Then elsewhere in the code (at the Engine level I guess, haven't
explored it yet) I'd need to make changes so that it was prepared to
handle multiple buffers instead of just one. Evidently I'd need to
change the code wherever it assumed a single buffer and replace that
with an Array. Probably haven't explained my idea very well but
hopefully you get some idea of what I'm suggesting.
It's just an idea which I haven't tried to put into practice yet so it
might be flawed.
Cheers,
Wincent