Package genshi :: Package template :: Module loader

Module loader

Template loading and caching.
Classes
  TemplateNotFound
Exception raised when a specific template file could not be found.
  TemplateLoader
Responsible for loading templates from files on the specified search path.
Functions
function
directory(path)
Loader factory for loading templates from a local directory.
function
package(name, path)
Loader factory for loading templates from egg package data.
function
prefixed(**delegates)
Factory for a load function that delegates to other loaders depending on the prefix of the requested template path.
Function Details

directory(path)

 
Loader factory for loading templates from a local directory.
Parameters:
  • path - the path to the local directory containing the templates
Returns: function
the loader function to load templates from the given directory

package(name, path)

 
Loader factory for loading templates from egg package data.
Parameters:
  • name - the name of the package containing the resources
  • path - the path inside the package data
Returns: function
the loader function to load templates from the given package

prefixed(**delegates)

 

Factory for a load function that delegates to other loaders depending on the prefix of the requested template path.

The prefix is stripped from the filename when passing on the load request to the delegate.

>>> load = prefixed(
...     app1 = lambda filename: ('app1', filename, None, None),
...     app2 = lambda filename: ('app2', filename, None, None)
... )
>>> print(load('app1/foo.html'))
('app1', 'app1/foo.html', None, None)
>>> print(load('app2/bar.html'))
('app2', 'app2/bar.html', None, None)
Parameters:
  • delegates - mapping of path prefixes to loader functions
Returns: function
the loader function