betty.jinja2 package

Submodules

Module contents

Provide rendering utilities using Jinja2.

class betty.jinja2.EntityContexts(*entities)[source]

Bases: object

Parameters:
*entities

class betty.jinja2.Environment(app)[source]

Bases: Environment

Parameters:
app

filters : --is-rst--dict[str, Callable[..., Any]]
globals : --is-rst--dict[str, Any]
template_class

alias of Template

tests : --is-rst--dict[str, Callable[..., bool]]
class betty.jinja2.Jinja2Provider[source]

Bases: object

property filters : dict[str, Callable[[...], Any]]
property globals : dict[str, Any]
property tests : dict[str, Callable[[...], bool]]
class betty.jinja2.Jinja2Renderer(environment, configuration)[source]

Bases: Renderer

Parameters:
environment

configuration

property file_extensions : set[str]
async render_file(file_path, *, job_context=None, localizer=None)[source]
Parameters:
file_path

job_context=None

localizer=None

Return type:

pathlib.Path

class betty.jinja2.Template(source: str | ~jinja2.nodes.Template, block_start_string: str = '{%', block_end_string: str = '%}', variable_start_string: str = '{{', variable_end_string: str = '}}', comment_start_string: str = '{#', comment_end_string: str = '#}', line_statement_prefix: str | None = None, line_comment_prefix: str | None = None, trim_blocks: bool = False, lstrip_blocks: bool = False, newline_sequence: te.Literal['\n', '\r\n', '\r'] = '\n', keep_trailing_newline: bool = False, extensions: ~typing.Sequence[str | ~typing.Type[Extension]] = (), optimized: bool = True, undefined: ~typing.Type[~jinja2.runtime.Undefined] = <class 'jinja2.runtime.Undefined'>, finalize: ~typing.Callable[[...], ~typing.Any] | None = None, autoescape: bool | ~typing.Callable[[str | None], bool] = False, enable_async: bool = False)[source]

Bases: Template

environment : --is-rst--Environment
environment_class

alias of Environment

new_context(vars=None, shared=False, locals=None)[source]

Create a new Context for this template. The vars provided will be passed to the template. Per default the globals are added to the context. If shared is set to True the data is passed as is to the context without adding the globals.

locals can be a dict of local variables for internal usage.

Parameters:
vars=None

shared=False

locals=None

Return type:

jinja2.runtime.Context

betty.jinja2.context_app(context)[source]

Get the current app from the Jinja2 context.

Parameters:
context

Return type:

betty.app.App

betty.jinja2.context_job_context(context)[source]

Get the current job context from the Jinja2 context.

Parameters:
context

Return type:

betty.job.Context | None

betty.jinja2.context_localizer(context)[source]

Get the current localizer from the Jinja2 context.

Parameters:
context

Return type:

betty.locale.Localizer