From: Armin Ronacher Date: Sat, 29 May 2010 19:48:24 +0000 (+0200) Subject: Added hooks for compilation and generation. This fixes #384 X-Git-Tag: 2.5~7 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=78efe7401b1f49fc1a72fc33ed6b6b97767cec44;p=jinja2.git Added hooks for compilation and generation. This fixes #384 --HG-- branch : trunk --- 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 = '