blob: 80bbc628a050ee9f77cafa1fc4d140452c169d79 [file] [log] [blame]
Armin Ronacher27069d72008-05-11 19:48:12 +02001#!/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 Ronacherae8a9302010-02-17 00:30:01 +01009 :copyright: Copyright 2010 by Armin Ronacher.
Armin Ronacher27069d72008-05-11 19:48:12 +020010 :license: BSD.
11"""
12import sys
13import jinja2
14from werkzeug import script
15
Armin Ronacher5c047ea2008-05-23 22:26:45 +020016env = jinja2.Environment(extensions=['jinja2.ext.i18n', 'jinja2.ext.do',
Armin Ronacher067879e2011-05-24 16:40:09 +020017 'jinja2.ext.loopcontrols',
18 'jinja2.ext.with_',
19 'jinja2.ext.autoescape'],
20 autoescape=True)
Armin Ronacher27069d72008-05-11 19:48:12 +020021
22def 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
36def action_compile():
37 print env.compile(sys.stdin.read(), raw=True)
38
39action_shell = script.make_shell(shell_init_func)
40
41
42if __name__ == '__main__':
43 script.run()