vinegar.template

Sub modules

jinja

Support for Jinja templates (using the Jinja 2 library).

Module API

Renderers for various template languages.

Template engines are used to render template files, enriching them with information provided through a context. They are the primary way of generating customized files based on configuration information.

The vinegar.template.jinja module provides a template engine using the powerful Jinja 2 library. An instance of that engine can be retrieved by calling get_template_engine with name set to jinja.

All template engine modules have in common that they must specify a get_instance function that takes a dict with configuration data as its only parameter. This function must return an instance of TemplateEngine.

Template engines are thread safe.

class vinegar.template.TemplateEngine

Renderer for template files.

A template engine is used to read template files and provide the output of the rendering process.

Each template engine has to implement the render method. This method is used to read a template file and returns is rendering result as a string.

Template engines have to be implemented in a thread-safe manner, so that render can safely be used by different threads.

abstract render(template_path: str, context: Mapping[str, Any]) str

Render the template file specified by template_path and return the result.

Parameters:

template_path – path to the template file.

Param:

context: context available to the template. The objects supplied by this mapping should be made available to the template code when rendering. The details of how the context objects are made available depends on the template engine.

Returns:

result of rendering the template.

vinegar.template.get_template_engine(name: str, config: Mapping[Any, Any]) TemplateEngine

Create the an instance of the template engine with the specified name, using the specified configuration.

Parameters:

name – name of the template engine. If the name contains a dot, it is treated as an absolute module name. Otherwise it is treated as a name of one of the modules inside the vinegar.template module.

Param:

config: configuration data for the template engine. The meaning of that data is up to the implementation of the template engine.

Returns:

newly created template engine.