Armin Ronacher | 27069d7 | 2008-05-11 19:48:12 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # -*- coding: utf-8 -*- |
| 3 | """ |
| 4 | Jinja2 Debug Interface |
| 5 | ~~~~~~~~~~~~~~~~~~~~~~ |
| 6 | |
| 7 | Helper script for internal Jinja2 debugging. Requires Werkzeug. |
| 8 | |
Armin Ronacher | ae8a930 | 2010-02-17 00:30:01 +0100 | [diff] [blame] | 9 | :copyright: Copyright 2010 by Armin Ronacher. |
Armin Ronacher | 27069d7 | 2008-05-11 19:48:12 +0200 | [diff] [blame] | 10 | :license: BSD. |
| 11 | """ |
| 12 | import sys |
| 13 | import jinja2 |
| 14 | from werkzeug import script |
| 15 | |
Armin Ronacher | 5c047ea | 2008-05-23 22:26:45 +0200 | [diff] [blame] | 16 | env = jinja2.Environment(extensions=['jinja2.ext.i18n', 'jinja2.ext.do', |
Armin Ronacher | 067879e | 2011-05-24 16:40:09 +0200 | [diff] [blame] | 17 | 'jinja2.ext.loopcontrols', |
| 18 | 'jinja2.ext.with_', |
| 19 | 'jinja2.ext.autoescape'], |
| 20 | autoescape=True) |
Armin Ronacher | 27069d7 | 2008-05-11 19:48:12 +0200 | [diff] [blame] | 21 | |
| 22 | def shell_init_func(): |
| 23 | def _compile(x): |
| 24 | print env.compile(x, raw=True) |
| 25 | result = { |
| 26 | 'e': env, |
| 27 | 'c': _compile, |
| 28 | 't': env.from_string, |
| 29 | 'p': env.parse |
| 30 | } |
| 31 | for key in jinja2.__all__: |
| 32 | result[key] = getattr(jinja2, key) |
| 33 | return result |
| 34 | |
| 35 | |
| 36 | def action_compile(): |
| 37 | print env.compile(sys.stdin.read(), raw=True) |
| 38 | |
| 39 | action_shell = script.make_shell(shell_init_func) |
| 40 | |
| 41 | |
| 42 | if __name__ == '__main__': |
| 43 | script.run() |