From 0b51462ce4b5bcaafbf8f3b327b85f135f19d83e Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Tue, 20 Mar 2007 19:58:21 +0100 Subject: [PATCH] [svn] implemented GeneralTemplateInterface --HG-- branch : trunk --- jinja/__init__.py | 2 +- jinja/loaders.py | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/jinja/__init__.py b/jinja/__init__.py index cc60b4a..e87d195 100644 --- a/jinja/__init__.py +++ b/jinja/__init__.py @@ -7,6 +7,6 @@ :license: BSD, see LICENSE for more details. """ from jinja.environment import Environment +from jinja.plugin import jinja_plugin_factory as template_plugin_factory from jinja.loaders import * - from_string = Environment().from_string diff --git a/jinja/loaders.py b/jinja/loaders.py index ff701a9..0c5168e 100644 --- a/jinja/loaders.py +++ b/jinja/loaders.py @@ -361,11 +361,39 @@ class FunctionLoader(CachedLoaderMixin, BaseLoader): load. If it returns a string or unicode object it's used to load a template. If the return value is None it's considered missing. + ``getmtime_func`` Function used to check if templates requires + reloading. Has to return the UNIX timestamp of + the last template change or 0 if this template + does not exist or requires updates at any cost. + ``use_memcache`` Set this to ``True`` to enable memory caching. + This is usually a good idea in production mode, + but disable it during development since it won't + reload template changes automatically. + This only works in persistent environments like + FastCGI. + ``memcache_size`` Number of template instance you want to cache. + Defaults to ``40``. + ``cache_folder`` Set this to an existing directory to enable + caching of templates on the file system. Note + that this only affects templates transformed + into python code. Default is ``None`` which means + that caching is disabled. + ``auto_reload`` Set this to `False` for a slightly better + performance. In that case of `getmtime_func` + not being provided this won't have an effect. =================== ================================================= """ - def __init__(self, loader_func): + def __init__(self, loader_func, getmtime_func=None, use_memcache=False, + memcache_size=40, cache_folder=None, auto_reload=True): + # when changing the signature also check the jinja.plugin function + # loader instantiation. self.loader_func = loader_func + self.getmtime_func = getmtime_func + if auto_reload and getmtime_func is None: + auto_reload = False + CachedLoaderMixin.__init__(self, use_memcache, memcache_size, + cache_folder, auto_reload) def get_source(self, environment, name, parent): rv = self.loader_func(name) @@ -375,6 +403,9 @@ class FunctionLoader(CachedLoaderMixin, BaseLoader): return rv.decode(environment.template_charset) return rv + def check_source_changed(self, environment, name): + return self.getmtime_func(name) + class DictLoader(BaseLoader): """ -- 2.26.2