From 78efe7401b1f49fc1a72fc33ed6b6b97767cec44 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sat, 29 May 2010 21:48:24 +0200 Subject: [PATCH] Added hooks for compilation and generation. This fixes #384 --HG-- branch : trunk --- jinja2/environment.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/jinja2/environment.py b/jinja2/environment.py index 03aef1a..c8abd51 100644 --- a/jinja2/environment.py +++ b/jinja2/environment.py @@ -433,6 +433,22 @@ class Environment(object): stream = TokenStream(stream, name, filename) return stream + def _generate(self, source, name, filename, defer_init=False): + """Internal hook that can be overriden to hook a different generate + method in. + + .. versionadded:: 2.5 + """ + return generate(source, self, name, filename, defer_init=defer_init) + + def _compile(self, source, filename): + """Internal hook that can be overriden to hook a different compile + method in. + + .. versionadded:: 2.5 + """ + return compile(source, filename, 'exec') + @internalcode def compile(self, source, name=None, filename=None, raw=False, defer_init=False): @@ -462,15 +478,15 @@ class Environment(object): source = self._parse(source, name, filename) if self.optimized: source = optimize(source, self) - source = generate(source, self, name, filename, - defer_init=defer_init) + source = self._generate(source, name, filename, + defer_init=defer_init) if raw: return source if filename is None: filename = '