Source code for httk.serve.web.templating.base

"""Define template render inputs and the engine protocol."""

from dataclasses import dataclass
from typing import Protocol


@dataclass(frozen=True)
[docs] class TemplateRenderInput: """Carry page content and context into a template engine. :param content_html: Rendered page HTML supplied to the template. :param template_name: Optional content template name. :param base_template_name: Optional base template name. :param context: Values exposed to templates. """
[docs] content_html: str
[docs] template_name: str | None
[docs] base_template_name: str | None
[docs] context: dict[str, object]
[docs] class TemplateEngine(Protocol): """Define the page and fragment template-engine protocol."""
[docs] def render(self, render_input: TemplateRenderInput) -> str: """Render page content through the configured templates.""" ...
[docs] def render_fragment(self, *, template_name: str, context: dict[str, object]) -> str | None: """Render one optional fragment template.""" ...