Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes
MoinMoin.support.werkzeug.contrib.kickstart.GenshiTemplateLoader Class Reference
Inheritance diagram for MoinMoin.support.werkzeug.contrib.kickstart.GenshiTemplateLoader:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.support.werkzeug.contrib.kickstart.GenshiTemplateLoader:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def get_template
def render_to_string
def render_to_response

Public Attributes

 not_found_exception
 loader
 output_type
 encoding
 search_path

Detailed Description

A unified interface for loading Genshi templates. Actually a quite thin
wrapper for Genshi's TemplateLoader.

It sets some defaults that differ from the Genshi loader, most notably
auto_reload is active. All imporant options can be passed through to
Genshi.
The default output type is 'html', but can be adjusted easily by changing
the `output_type` attribute.

Definition at line 235 of file kickstart.py.


Constructor & Destructor Documentation

def MoinMoin.support.werkzeug.contrib.kickstart.GenshiTemplateLoader.__init__ (   self,
  search_path,
  encoding = 'utf-8',
  kwargs 
)

Definition at line 245 of file kickstart.py.

00245 
00246     def __init__(self, search_path, encoding='utf-8', **kwargs):
00247         TemplateLoader.__init__(self, search_path, encoding)
00248         # import Genshi here, because we don't want a general Genshi
00249         # dependency, only a local one
00250         from genshi.template import TemplateLoader as GenshiLoader
00251         from genshi.template.loader import TemplateNotFound
00252 
00253         self.not_found_exception = TemplateNotFound
00254         # set auto_reload to True per default
00255         reload_template = kwargs.pop('auto_reload', True)
00256         # get rid of default_encoding as this template loaders overwrites it
00257         # with the value of encoding
00258         kwargs.pop('default_encoding', None)
00259 
00260         # now, all arguments are clean, pass them on
00261         self.loader = GenshiLoader(search_path, default_encoding=encoding,
00262                 auto_reload=reload_template, **kwargs)
00263 
00264         # the default output is HTML but can be overridden easily
00265         self.output_type = 'html'
00266         self.encoding = encoding


Member Function Documentation

Get the template which is at the given name

Reimplemented from MoinMoin.support.werkzeug.contrib.kickstart.TemplateLoader.

Definition at line 267 of file kickstart.py.

00267 
00268     def get_template(self, template_name):
00269         """Get the template which is at the given name"""
00270         try:
00271             return self.loader.load(template_name, encoding=self.encoding)
00272         except self.not_found_exception, e:
00273             # catch the exception raised by Genshi, convert it into a werkzeug
00274             # exception (for the sake of consistency)
00275             raise TemplateNotFound(template_name)

def MoinMoin.support.werkzeug.contrib.kickstart.TemplateLoader.render_to_response (   self,
  args,
  kwargs 
) [inherited]
Load and render a template into a response object.

Definition at line 222 of file kickstart.py.

00222 
00223     def render_to_response(self, *args, **kwargs):
00224         """Load and render a template into a response object."""
00225         return Response(self.render_to_string(*args, **kwargs))

Here is the call graph for this function:

def MoinMoin.support.werkzeug.contrib.kickstart.GenshiTemplateLoader.render_to_string (   self,
  template_name,
  context = None 
)
Load and render a template into an unicode string

Reimplemented from MoinMoin.support.werkzeug.contrib.kickstart.TemplateLoader.

Definition at line 276 of file kickstart.py.

00276 
00277     def render_to_string(self, template_name, context=None):
00278         """Load and render a template into an unicode string"""
00279         # create an empty context if no context was specified
00280         context = context or {}
00281         tmpl = self.get_template(template_name)
00282         # render the template into a unicode string (None means unicode)
00283         return tmpl. \
00284             generate(**context). \
00285             render(self.output_type, encoding=None)

Here is the call graph for this function:


Member Data Documentation

Reimplemented from MoinMoin.support.werkzeug.contrib.kickstart.TemplateLoader.

Definition at line 265 of file kickstart.py.

Definition at line 260 of file kickstart.py.

Definition at line 252 of file kickstart.py.

Definition at line 264 of file kickstart.py.

Definition at line 211 of file kickstart.py.


The documentation for this class was generated from the following file: