changeset 538:e9db4aca70f0 trunk

Add `loader_callback` option to plugin interface as requested in #130.
author cmlenz
date Thu, 28 Jun 2007 17:04:54 +0000
parents 8227900a442c
children 6b413fbf359a
files ChangeLog doc/plugin.txt genshi/template/plugin.py
diffstat 3 files changed, 21 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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
--- 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
Copyright (C) 2012-2017 Edgewall Software