comparison markup/template.py @ 90:c835e81c50af trunk

When an expression evaluates to a callable, it is called implicitly.
author cmlenz
date Wed, 19 Jul 2006 17:50:17 +0000
parents 80386d62814f
children 01d36818bb3d
comparison
equal deleted inserted replaced
89:80386d62814f 90:c835e81c50af
271 >>> ctxt = Context(bar='Bye') 271 >>> ctxt = Context(bar='Bye')
272 >>> tmpl = Template('''<div xmlns:py="http://markup.edgewall.org/"> 272 >>> tmpl = Template('''<div xmlns:py="http://markup.edgewall.org/">
273 ... <p py:def="echo(greeting, name='world')" class="message"> 273 ... <p py:def="echo(greeting, name='world')" class="message">
274 ... ${greeting}, ${name}! 274 ... ${greeting}, ${name}!
275 ... </p> 275 ... </p>
276 ... ${echo('hi', name='you')} 276 ... ${echo('Hi', name='you')}
277 ... </div>''') 277 ... </div>''')
278 >>> print tmpl.generate(ctxt) 278 >>> print tmpl.generate(ctxt)
279 <div> 279 <div>
280 <p class="message"> 280 <p class="message">
281 hi, you! 281 Hi, you!
282 </p> 282 </p>
283 </div> 283 </div>
284 284
285 If a function does not require parameters, the parenthesis can be omitted
286 both when defining and when calling it:
287
285 >>> ctxt = Context(bar='Bye') 288 >>> ctxt = Context(bar='Bye')
286 >>> tmpl = Template('''<div xmlns:py="http://markup.edgewall.org/"> 289 >>> tmpl = Template('''<div xmlns:py="http://markup.edgewall.org/">
287 ... <p py:def="echo(greeting, name='world')" class="message"> 290 ... <p py:def="helloworld" class="message">
288 ... ${greeting}, ${name}! 291 ... Hello, world!
289 ... </p> 292 ... </p>
290 ... <div py:replace="echo('hello')"></div> 293 ... ${helloworld}
291 ... </div>''') 294 ... </div>''')
292 >>> print tmpl.generate(ctxt) 295 >>> print tmpl.generate(ctxt)
293 <div> 296 <div>
294 <p class="message"> 297 <p class="message">
295 hello, world! 298 Hello, world!
296 </p> 299 </p>
297 </div> 300 </div>
298 """ 301 """
299 __slots__ = ['name', 'args', 'defaults', 'stream', 'directives'] 302 __slots__ = ['name', 'args', 'defaults', 'stream', 'directives']
300 303
Copyright (C) 2012-2017 Edgewall Software