diff options
author | Armin Ronacher <armin.ronacher@active-4.com> | 2008-05-07 15:39:39 +0200 |
---|---|---|
committer | Armin Ronacher <armin.ronacher@active-4.com> | 2008-05-07 15:39:39 +0200 |
commit | 612b3a88e269f3ff6528f8aca4e65d332aba2974 (patch) | |
tree | 170e7523979870ec96b820b9faf310093d6ed67f /examples | |
parent | 5cdc1ac3d936f54811422c1b78b33dd0fa37a317 (diff) | |
download | jinja2-612b3a88e269f3ff6528f8aca4e65d332aba2974.tar.gz |
moved example code around
--HG--
branch : trunk
rename : examples/cycle.py => examples/basic/cycle.py
rename : examples/debugger.py => examples/basic/debugger.py
rename : examples/inheritance.py => examples/basic/inheritance.py
rename : examples/templates/broken.html => examples/basic/templates/broken.html
rename : examples/test.py => examples/basic/test.py
rename : examples/test_filter_and_linestatements.py => examples/basic/test_filter_and_linestatements.py
rename : examples/test_loop_filter.py => examples/basic/test_loop_filter.py
rename : examples/translate.py => examples/basic/translate.py
Diffstat (limited to 'examples')
-rw-r--r-- | examples/basic/cycle.py (renamed from examples/cycle.py) | 0 | ||||
-rw-r--r-- | examples/basic/debugger.py (renamed from examples/debugger.py) | 0 | ||||
-rw-r--r-- | examples/basic/inheritance.py (renamed from examples/inheritance.py) | 0 | ||||
-rw-r--r-- | examples/basic/templates/broken.html (renamed from examples/templates/broken.html) | 0 | ||||
-rw-r--r-- | examples/basic/test.py (renamed from examples/test.py) | 0 | ||||
-rw-r--r-- | examples/basic/test_filter_and_linestatements.py (renamed from examples/test_filter_and_linestatements.py) | 0 | ||||
-rw-r--r-- | examples/basic/test_loop_filter.py (renamed from examples/test_loop_filter.py) | 0 | ||||
-rw-r--r-- | examples/basic/translate.py (renamed from examples/translate.py) | 0 | ||||
-rw-r--r-- | examples/profile.py | 56 |
9 files changed, 56 insertions, 0 deletions
diff --git a/examples/cycle.py b/examples/basic/cycle.py index 73dd632..73dd632 100644 --- a/examples/cycle.py +++ b/examples/basic/cycle.py diff --git a/examples/debugger.py b/examples/basic/debugger.py index 52a8be2..52a8be2 100644 --- a/examples/debugger.py +++ b/examples/basic/debugger.py diff --git a/examples/inheritance.py b/examples/basic/inheritance.py index aa687c8..aa687c8 100644 --- a/examples/inheritance.py +++ b/examples/basic/inheritance.py diff --git a/examples/templates/broken.html b/examples/basic/templates/broken.html index bbd5bf4..bbd5bf4 100644 --- a/examples/templates/broken.html +++ b/examples/basic/templates/broken.html diff --git a/examples/test.py b/examples/basic/test.py index b62c84f..b62c84f 100644 --- a/examples/test.py +++ b/examples/basic/test.py diff --git a/examples/test_filter_and_linestatements.py b/examples/basic/test_filter_and_linestatements.py index c9e8f95..c9e8f95 100644 --- a/examples/test_filter_and_linestatements.py +++ b/examples/basic/test_filter_and_linestatements.py diff --git a/examples/test_loop_filter.py b/examples/basic/test_loop_filter.py index 49c2efc..49c2efc 100644 --- a/examples/test_loop_filter.py +++ b/examples/basic/test_loop_filter.py diff --git a/examples/translate.py b/examples/basic/translate.py index 3358765..3358765 100644 --- a/examples/translate.py +++ b/examples/basic/translate.py diff --git a/examples/profile.py b/examples/profile.py new file mode 100644 index 0000000..843efb1 --- /dev/null +++ b/examples/profile.py @@ -0,0 +1,56 @@ +try: + from cProfile import Profile +except ImportError: + from profile import Profile +from pstats import Stats +from jinja2 import Environment as JinjaEnvironment + +context = { + 'page_title': 'mitsuhiko\'s benchmark', + 'table': [dict(a=1,b=2,c=3,d=4,e=5,f=6,g=7,h=8,i=9,j=10) for x in range(1000)] +} + +jinja_template = JinjaEnvironment( + line_statement_prefix='%', + variable_start_string="${", + variable_end_string="}" +).from_string("""\ +<!doctype html> +<html> + <head> + <title>${page_title|e}</title> + </head> + <body> + <div class="header"> + <h1>${page_title|e}</h1> + </div> + <ul class="navigation"> + % for href, caption in [ + ('index.html', 'Index'), + ('downloads.html', 'Downloads'), + ('products.html', 'Products') + ] + <li><a href="${href|e}">${caption|e}</a></li> + % endfor + </ul> + <div class="table"> + <table> + % for row in table + <tr> + % for cell in row + <td>${cell}</td> + % endfor + </tr> + % endfor + </table> + </div> + </body> +</html>\ +""") + + +p = Profile() +p.runcall(lambda: jinja_template.render(context)) +stats = Stats(p) +stats.sort_stats('time', 'calls') +stats.print_stats() |