Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions fasthx/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def get_component(self, request: Request, error: Exception | None) -> str:

@dataclass(frozen=True, slots=True)
class Jinja:
"""Jinja2 (renderer) decorator factory."""
"""Jinja2 renderer utility with FastAPI route decorators."""

templates: Jinja2Templates
"""The Jinja2 templates of the application."""
Expand All @@ -286,18 +286,18 @@ def hx(
template: ComponentSelector[str],
*,
error_template: ComponentSelector[str] | None = None,
no_data: bool = False,
make_context: JinjaContextFactory | None = None,
no_data: bool = False,
prefix: str | None = None,
) -> Callable[[MaybeAsyncFunc[P, Any]], Callable[P, Coroutine[None, None, Any | Response]]]:
"""
Decorator for rendering a route's return value to HTML using the Jinja2 template
with the given name, if the request was an HTMX one.
Decorator for rendering a route's result if the request was an HTMX one.

Arguments:
template: The Jinja2 template selector to use.
no_data: If set, the route will only accept HTMX requests.
error_template: The Jinja2 template selector to use for route error rendering.
make_context: Route-specific override for the `make_context` property.
no_data: If set, the route will only accept HTMX requests.
prefix: Optional template name prefix.

Returns:
Expand Down Expand Up @@ -326,12 +326,13 @@ def page(
prefix: str | None = None,
) -> Callable[[MaybeAsyncFunc[P, Any]], Callable[P, Coroutine[None, None, Any | Response]]]:
"""
Decorator for rendering a route's return value to HTML using the Jinja2 template
with the given name. This decorator triggers HTML rendering regardless of whether
the request was HTMX or not.
Decorator for rendering a route's result.

This decorator triggers HTML rendering regardless of whether the request was HTMX or not.

Arguments:
template: The Jinja2 template selector to use.
error_template: The Jinja2 template selector to use for route error rendering.
make_context: Route-specific override for the `make_context` property.
prefix: Optional template name prefix.
"""
Expand Down