OpenQuizz
Une application de gestion des contenus pédagogiques
FunctionLoader Class Reference
Inheritance diagram for FunctionLoader:
Collaboration diagram for FunctionLoader:

Public Member Functions

def __init__ (self, load_func)
 
def get_source (self, environment, template)
 
- Public Member Functions inherited from BaseLoader
def list_templates (self)
 
def load (self, environment, name, globals=None)
 

Data Fields

 load_func
 

Additional Inherited Members

- Static Public Attributes inherited from BaseLoader
 has_source_access
 

Detailed Description

A loader that is passed a function which does the loading.  The
function receives the name of the template and has to return either
an unicode string with the template source, a tuple in the form ``(source,
filename, uptodatefunc)`` or `None` if the template does not exist.

>>> def load_template(name):
...     if name == 'index.html':
...         return '...'
...
>>> loader = FunctionLoader(load_template)

The `uptodatefunc` is a function that is called if autoreload is enabled
and has to return `True` if the template is still up to date.  For more
details have a look at :meth:`BaseLoader.get_source` which has the same
return value.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  load_func 
)

Member Function Documentation

◆ get_source()

def get_source (   self,
  environment,
  template 
)
Get the template source, filename and reload helper for a template.
It's passed the environment and template name and has to return a
tuple in the form ``(source, filename, uptodate)`` or raise a
`TemplateNotFound` error if it can't locate the template.

The source part of the returned tuple must be the source of the
template as unicode string or a ASCII bytestring.  The filename should
be the name of the file on the filesystem if it was loaded from there,
otherwise `None`.  The filename is used by python for the tracebacks
if no loader extension is used.

The last item in the tuple is the `uptodate` function.  If auto
reloading is enabled it's always called to check if the template
changed.  No arguments are passed so the function must store the
old state somewhere (for example in a closure).  If it returns `False`
the template will be reloaded.

Reimplemented from BaseLoader.

Field Documentation

◆ load_func

load_func

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