Templates¶
TemplateRenderer accepts an optional configured Renderer. Inject one when template
renders must use fonts registered on that renderer; when omitted, the template wrapper
creates a default renderer internally. It also accepts a complete Jinja Environment
instead of template_dir, preserving native loaders, globals, tests, extensions,
undefined-value policies, caches, and other Jinja configuration.
takumi_py.template.TemplateRenderer ¶
__init__ ¶
__init__(
template_dir: str | Path | None = None,
*,
filters: Mapping[str, Filter] | None = None,
renderer: Renderer | None = None,
environment: Environment | None = None,
) -> None
render ¶
render(
template_name: str,
context: Mapping[str, object],
*,
stylesheets: Sequence[str] | None = None,
keyframes: KeyframesInput | None = None,
html_options: HtmlOptions | None = None,
options: RenderOptions | None = None,
width: int | UnsetType | None = UNSET,
height: int | UnsetType | None = UNSET,
format: ImageOutputFormat | UnsetType = UNSET,
quality: int | UnsetType | None = UNSET,
lossless: bool | UnsetType | None = UNSET,
font_size: float | UnsetType = UNSET,
device_pixel_ratio: float | UnsetType = UNSET,
draw_debug_border: bool | UnsetType = UNSET,
time_ms: int | UnsetType = UNSET,
dithering: DitheringAlgorithm | UnsetType = UNSET,
images: Sequence[ImageResourceInput]
| UnsetType
| None = UNSET,
font_families: Sequence[str] | UnsetType | None = UNSET,
lang: str | UnsetType | None = UNSET,
) -> bytes
render_template_to_html¶
Use this standalone helper when the caller needs rendered HTML without image output.
It accepts either template_dir or a caller-owned Jinja environment, plus the same
custom-filter mapping. For image output with custom renderer state, prefer
TemplateRenderer(..., renderer=renderer).
takumi_py.template.render_template_to_html ¶
render_template_to_html(
template_name: str,
context: Mapping[str, object],
*,
template_dir: str | Path | None = None,
filters: Mapping[str, Filter] | None = None,
environment: Environment | None = None,
) -> str