Template Engine Modules

Author:Juti Noppornpitak

This package is used for rendering.

class tori.template.renderer.DefaultRenderer(*referers)

The default renderer with Jinja2

Parameters:referers – the template module path (e.g., com.shiroyuki.view) or multiple base paths of Jinja templates based on the current working directory.

For example:

# Instantiate with the module path.
renderer = DefaultRenderer('app.views')

# Instantiate with multiple base paths of Jinja templates.
renderer = DefaultRenderer('/opt/app/ui/template', '/usr/local/tori/module/template')
render(template_path, **contexts)

See Renderer.render() for more information.

class tori.template.renderer.Renderer(*args, **kwargs)

The abstract renderer for Tori framework.

Warning

This is a non-working renderer. To use the built-in renderer (with Jinja2), try DefaultRenderer. Otherwise, you should be expecting tori.exception.FutureFeatureException.

render(template_path, **contexts)

Render a template with context variables.

Parameters:
  • template_path (string or unicode) – a path to the template
  • contexts – a dictionary of context variables.
Return type:

string or unicode

Example:

renderer = Renderer()
renderer.render('dummy.html', appname='ikayaki', version=1.0)
Author:Juti Noppornpitaks
Restriction:Internal Use Only
class tori.template.repository.Repository(class_reference)

The template repository used by Rendering Service.

Parameters:class_reference (tori.template.service.RenderingService) – class reference

Note

This class is designed as a strict-type collection and may be refactored to the common area later on.

get(renderer_name)

Retrieve the renderer by name.

Parameters:renderer_name (string or unicode) – the name of the renderer.
Return type:tori.template.renderer.Renderer
set(renderer)

Register the renderer.

Returns:self
Author:Juti Noppornpitak
Restriction:Internal Use Only

This package contains the rendering service. This is a module automatically loaded by tori.application.Application.

class tori.template.service.RenderingService(renderer_class=<class 'tori.template.renderer.Renderer'>, repository_class=<class 'tori.template.repository.Repository'>)

The rendering service allows the access to all template repositories.

This acts as a controller.

Parameters:
register(renderer)

Register a renderer.

Parameters:renderer (tori.template.renderer.Renderer) – the renderer
Returns:self.
render(repository_name, template_path, **contexts)

Render a template from a repository repository_name.

As this method acts as a shortcut and wrapper to the actual renderer for the given repository, see tori.template.renderer.Renderer.render() for more information.

Return type:string
use(repository_name)

Retrieve the renderer by name

Parameters:repository_name (str) – the name of the repository
Return type:tori.template.renderer.Renderer
Read the Docs v: v2.1
Versions
latest
v2.1
v2.0
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.