comparison genshi/template/directives.py @ 355:94639584725a experimental-inline

inline branch: Merged [430:434/trunk].
author cmlenz
date Mon, 13 Nov 2006 18:16:57 +0000
parents ffa7dea6e8fd
children a81675590258
comparison
equal deleted inserted replaced
350:4a2050e9dcd8 355:94639584725a
112 <li>Bye</li> 112 <li>Bye</li>
113 </ul> 113 </ul>
114 """ 114 """
115 __slots__ = [] 115 __slots__ = []
116 116
117 def __call__(self, stream, ctxt, directives): 117 def prepare(self, directives, stream):
118 def _generate(): 118 directives.remove(self)
119 yield stream.next() 119 return [stream[0], (EXPR, self.expr, (None, -1, --1)), stream[-1]]
120 yield EXPR, self.expr, (None, -1, -1)
121 event = stream.next()
122 for next in stream:
123 event = next
124 yield event
125
126 return _apply_directives(_generate(), ctxt, directives)
127 120
128 121
129 class DefDirective(Directive): 122 class DefDirective(Directive):
130 """Implementation of the `py:def` template directive. 123 """Implementation of the `py:def` template directive.
131 124
366 Bye 359 Bye
367 </div> 360 </div>
368 """ 361 """
369 __slots__ = [] 362 __slots__ = []
370 363
371 def __call__(self, stream, ctxt, directives): 364 def prepare(self, directives, stream):
372 yield EXPR, self.expr, (None, -1, -1) 365 directives.remove(self)
366 return [(EXPR, self.expr, (None, -1, -1))]
373 367
374 368
375 class StripDirective(Directive): 369 class StripDirective(Directive):
376 """Implementation of the `py:strip` template directive. 370 """Implementation of the `py:strip` template directive.
377 371
405 """ 399 """
406 __slots__ = [] 400 __slots__ = []
407 401
408 def __call__(self, stream, ctxt, directives): 402 def __call__(self, stream, ctxt, directives):
409 def _generate(): 403 def _generate():
410 if self.expr: 404 if self.expr.evaluate(ctxt):
411 strip = self.expr.evaluate(ctxt)
412 else:
413 strip = True
414 if strip:
415 stream.next() # skip start tag 405 stream.next() # skip start tag
416 previous = stream.next() 406 previous = stream.next()
417 for event in stream: 407 for event in stream:
418 yield previous 408 yield previous
419 previous = event 409 previous = event
420 else: 410 else:
421 for event in stream: 411 for event in stream:
422 yield event 412 yield event
423
424 return _apply_directives(_generate(), ctxt, directives) 413 return _apply_directives(_generate(), ctxt, directives)
414
415 def prepare(self, directives, stream):
416 if not self.expr:
417 directives.remove(self)
418 return stream[1:-1]
419 return stream
425 420
426 421
427 class ChooseDirective(Directive): 422 class ChooseDirective(Directive):
428 """Implementation of the `py:choose` directive for conditionally selecting 423 """Implementation of the `py:choose` directive for conditionally selecting
429 one of several body elements to display. 424 one of several body elements to display.
Copyright (C) 2012-2017 Edgewall Software