Skip to content
Myr

[svn] implemented GeneralTemplateInterface

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent ca144da · Browse files · 2 files+33 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+33 added−2 removed

  • other:+33 added−2 removed

2 files+33 added−2 removed

modified:jinja/__init__.py+1 added-1 removed
5 unmodified lines
6 :copyright: 2007 by Armin Ronacher.7 :license: BSD, see LICENSE for more details.8"""9from jinja.environment import Environment10from jinja.plugin import jinja_plugin_factory as template_plugin_factory11from jinja.loaders import *1112from_string = Environment().from_string
modified:jinja/loaders.py+32 added-1 removed
359 unmodified lines
360 ``loader_func`` Function that takes the name of the template to361 load. If it returns a string or unicode object362 it's used to load a template. If the return363 value is None it's considered missing.364 ``getmtime_func`` Function used to check if templates requires365 reloading. Has to return the UNIX timestamp of366 the last template change or 0 if this template367 does not exist or requires updates at any cost.368 ``use_memcache`` Set this to ``True`` to enable memory caching.369 This is usually a good idea in production mode,370 but disable it during development since it won't371 reload template changes automatically.372 This only works in persistent environments like373 FastCGI.374 ``memcache_size`` Number of template instance you want to cache.375 Defaults to ``40``.376 ``cache_folder`` Set this to an existing directory to enable377 caching of templates on the file system. Note378 that this only affects templates transformed379 into python code. Default is ``None`` which means380 that caching is disabled.381 ``auto_reload`` Set this to `False` for a slightly better382 performance. In that case of `getmtime_func`383 not being provided this won't have an effect.384 =================== =================================================385 """386367 def __init__(self, loader_func):387 def __init__(self, loader_func, getmtime_func=None, use_memcache=False,388 memcache_size=40, cache_folder=None, auto_reload=True):389 # when changing the signature also check the jinja.plugin function390 # loader instantiation.391 self.loader_func = loader_func392 self.getmtime_func = getmtime_func393 if auto_reload and getmtime_func is None:394 auto_reload = False395 CachedLoaderMixin.__init__(self, use_memcache, memcache_size,396 cache_folder, auto_reload)397398 def get_source(self, environment, name, parent):399 rv = self.loader_func(name)400 if rv is None:
1 unmodified line
402 if isinstance(rv, str):403 return rv.decode(environment.template_charset)404 return rv405406 def check_source_changed(self, environment, name):407 return self.getmtime_func(name)408409410class DictLoader(BaseLoader):411 """412 Load templates from a given dict:413
57 unmodified lines