comparison examples/includes/run.py @ 21:eca77129518a

* Include paths are now interpreted relative to the path of the including template. Closes #3. * The filename is now included as first item in the `pos` tuple of stream events. * Simplified the "basic" example so that it actually ''is'' basic. * Added a more complex example using nested relative includes in [source:/trunk/examples/includes/ examples/includes].
author cmlenz
date Tue, 20 Jun 2006 13:05:37 +0000
parents
children 31b13ddf9f53
comparison
equal deleted inserted replaced
20:e3d3c1d8c98a 21:eca77129518a
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 from datetime import datetime, timedelta
5 import os
6 import sys
7 import timing
8
9 from markup.template import Context, TemplateLoader
10
11 def test():
12 base_path = os.path.dirname(os.path.abspath(__file__))
13 loader = TemplateLoader([os.path.join(base_path, 'skins'),
14 os.path.join(base_path, 'module'),
15 os.path.join(base_path, 'common')])
16
17 timing.start()
18 tmpl = loader.load('test.html')
19 timing.finish()
20 print ' --> parse stage: %dms' % timing.milli()
21
22 data = dict(hello='<world>', skin='default', hey='ZYX', bozz=None,
23 items=['Number %d' % num for num in range(1, 15)])
24
25 print tmpl.generate(Context(**data)).render(method='html')
26
27 times = []
28 for i in range(100):
29 timing.start()
30 list(tmpl.generate(Context(**data)))
31 timing.finish()
32 sys.stdout.write('.')
33 sys.stdout.flush()
34 times.append(timing.milli())
35 print
36
37 print ' --> render stage: %dms (avg), %dms (min), %dms (max)' % (
38 sum(times) / len(times), min(times), max(times))
39
40 if __name__ == '__main__':
41 if '-p' in sys.argv:
42 import hotshot, hotshot.stats
43 prof = hotshot.Profile("template.prof")
44 benchtime = prof.runcall(test)
45 stats = hotshot.stats.load("template.prof")
46 stats.strip_dirs()
47 stats.sort_stats('time', 'calls')
48 stats.print_stats()
49 else:
50 test()
Copyright (C) 2012-2017 Edgewall Software