Mercurial > genshi > mirror
diff genshi/template/directives.py @ 351:0cc031745884 trunk
The `py:content`, `py:replace`, and `py:strip=""` directives are now expanded when the template is loaded (as opposed to when it's rendered).
author | cmlenz |
---|---|
date | Fri, 10 Nov 2006 23:32:24 +0000 |
parents | 2aa7ca37ae6a |
children | fe40d34fb71d |
line wrap: on
line diff
--- a/genshi/template/directives.py +++ b/genshi/template/directives.py @@ -114,16 +114,9 @@ """ __slots__ = [] - def __call__(self, stream, ctxt, directives): - def _generate(): - yield stream.next() - yield EXPR, self.expr, (None, -1, -1) - event = stream.next() - for next in stream: - event = next - yield event - - return _apply_directives(_generate(), ctxt, directives) + def prepare(self, directives, stream): + directives.remove(self) + return [stream[0], (EXPR, self.expr, (None, -1, --1)), stream[-1]] class DefDirective(Directive): @@ -367,8 +360,9 @@ """ __slots__ = [] - def __call__(self, stream, ctxt, directives): - yield EXPR, self.expr, (None, -1, -1) + def prepare(self, directives, stream): + directives.remove(self) + return [(EXPR, self.expr, (None, -1, -1))] class StripDirective(Directive): @@ -406,11 +400,7 @@ def __call__(self, stream, ctxt, directives): def _generate(): - if self.expr: - strip = self.expr.evaluate(ctxt) - else: - strip = True - if strip: + if self.expr.evaluate(ctxt): stream.next() # skip start tag previous = stream.next() for event in stream: @@ -419,8 +409,13 @@ else: for event in stream: yield event + return _apply_directives(_generate(), ctxt, directives) - return _apply_directives(_generate(), ctxt, directives) + def prepare(self, directives, stream): + if not self.expr: + directives.remove(self) + return stream[1:-1] + return stream class ChooseDirective(Directive):