Modifying bindings


#1

Hello,

I have a little challenge that is frustrating me. I am trying to write
a wrapper around cache() so that my fragments get cached with comments
injected at the front and back. Unfortunately it is not as simple as
using “concat(text,block.bindings)” before and after the call to
cache() because then the comments themselves don’t get cached.

Here is what I have right now:

def wrap_cache(path,&block)
concat("", block.binding)
cache(path,&block)
concat("", block.binding)
end

It produces the correct visual output, but the concat results aren’t
part of the cached fragment, they are getting regenerated every time.
What I need to do is something like this:

def wrap_cache2(path,&block)
cache(path) do
concat(label_frag(‘vvvvvvvvv’,path),block.binding)
yield
concat(label_frag(’^^^^^^^^^’,path),block.binding)
end
end

But I need to give this new block the bindings of the original block,
rather than have it grab a new set of bindings. With the above,
cache() crashes b/c the inner block isn’t in the context of an erb
template, so it’s missing key stuff (specifically _erbout).

-Avram

“I realised something was wrong when I looked over and saw the mast in
the water.” - Dean Barker, Team New Zealand skipper