# HG changeset patch # User cmlenz # Date 1183050294 0 # Node ID 19c7dc1e4dd51661d5662d3dd5ee340df69d367c # Parent d0619ab2bcec2b0c6a6fccadef3faabd35efe7dc Add `loader_callback` option to plugin interface as requested in #130. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -19,6 +19,11 @@ * The I18n filter no longer extracts or translates literal strings in attribute values that also contain expressions. + * Added `loader_callback` option to plugin interface, which allows specifying + a callback function that the template loader should invoke whenever a new + template is loaded (ticket #130). Note that the value for this option can + not be specified as a string, only as an actual function object, which means + it is not available for use through configuration files. Version 0.4.2 diff --git a/doc/plugin.txt b/doc/plugin.txt --- a/doc/plugin.txt +++ b/doc/plugin.txt @@ -190,6 +190,16 @@ .. _`Understanding HTML, XML and XHTML`: http://webkit.org/blog/?p=68 +``genshi.loader_callback`` +-------------------------- +The callback function that should be invoked whenever the template loader loads +a new template. + +.. note:: Unlike the other options, this option can **not** be passed as + a string value, but rather must be a reference to the actual function. + That effectively means it can not be set from (non-Python) + configuration files. + ``genshi.lookup_errors`` ------------------------ The error handling style to use in template expressions. Can be either diff --git a/genshi/template/plugin.py b/genshi/template/plugin.py --- a/genshi/template/plugin.py +++ b/genshi/template/plugin.py @@ -58,6 +58,10 @@ raise ConfigurationError('Invalid value for max_cache_size: "%s"' % options.get('genshi.max_cache_size')) + loader_callback = options.get('genshi.loader_callback', None) + if loader_callback and not callable(loader_callback): + raise ConfigurationError('loader callback must be a function') + lookup_errors = options.get('genshi.lookup_errors', 'lenient') if lookup_errors not in ('lenient', 'strict'): raise ConfigurationError('Unknown lookup errors mode "%s"' % @@ -67,7 +71,8 @@ auto_reload=auto_reload, max_cache_size=max_cache_size, default_class=self.template_class, - variable_lookup=lookup_errors) + variable_lookup=lookup_errors, + callback=loader_callback) def load_template(self, templatename, template_string=None): """Find a template specified in python 'dot' notation, or load one from