pyechonext.template_engine package

Submodules

pyechonext.template_engine.builtin module

class pyechonext.template_engine.builtin.TemplateEngine(base_dir: str, templates_dir: str)[source]

Bases: object

This class describes a built-in template engine.

__init__(base_dir: str, templates_dir: str)[source]

Constructs a new instance.

Parameters:
  • base_dir (str) – The base dir

  • templates_dir (str) – The templates dir

build(context: dict, template_name: str) str[source]

Build template

Parameters:
  • context (dict) – The context

  • template_name (str) – The template name

Returns:

raw template string

Return type:

str

pyechonext.template_engine.builtin.render_template(request: Request, template_name: str, **kwargs) str[source]

Render template

Parameters:
  • request (Request) – The request

  • template_name (str) – The template name

  • kwargs (dictionary) – The keywords arguments

Returns:

raw template string

Return type:

str

Raises:

AssertionError – BASE_DIR and TEMPLATES_DIR is empty

pyechonext.template_engine.jinja module

class pyechonext.template_engine.jinja.TemplateEngine(base_dir: str, templates_dir: str)[source]

Bases: object

This class describes a jinja template engine.

__init__(base_dir: str, templates_dir: str)[source]

Constructs a new instance.

Parameters:
  • base_dir (str) – The base dir

  • templates_dir (str) – The templates dir

build(template_name: str, **kwargs)[source]
class pyechonext.template_engine.jinja.TemplateLoader(path: str)[source]

Bases: BaseLoader

This class describes a jinja2 template loader.

__init__(path: str)[source]

Constructs a new instance.

Parameters:

path (str) – The path

get_source(environment, template)[source]

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 a string. 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.

pyechonext.template_engine.jinja.render_template(request: Request, template_name: str, **kwargs) str[source]

Render template

Parameters:
  • request (Request) – The request

  • template_name (str) – The template name

  • kwargs (dictionary) – The keywords arguments

Returns:

raw template string

Return type:

str

Raises:

AssertionError – BASE_DIR and TEMPLATES_DIR is empty

Module contents