hack-house/.venv/lib/python3.12/site-packages/sanic_ext/extensions/templating/extension.py
leetcrypt bb1d662ee1 chore: rename project coven → hack-house ⛧
Rebrand the Rust client crate (coven/ → hh/, package+binary "hack-house"),
README, CLI strings, and branch (coven → hack-house). Gitea repo renamed
cmd-chat → hack-house to match. Crypto/server logic unchanged; selftest +
golden-vector test still green, binary is now `hack-house`.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-05-30 13:29:14 -07:00

58 lines
1.6 KiB
Python

from __future__ import annotations
import os
from collections import abc
from collections.abc import Sequence
from pathlib import Path
from typing import TYPE_CHECKING, Union
from jinja2 import (
Environment,
FileSystemLoader,
__version__,
select_autoescape,
)
from sanic_ext.extensions.templating.engine import Templating
from ..base import Extension
if TYPE_CHECKING:
from sanic_ext import Extend
class TemplatingExtension(Extension):
name = "templating"
def startup(self, bootstrap: Extend) -> None:
self._add_template_paths_to_reloader(
self.config.TEMPLATING_PATH_TO_TEMPLATES
)
loader = FileSystemLoader(self.config.TEMPLATING_PATH_TO_TEMPLATES)
if not hasattr(bootstrap, "environment"):
bootstrap.environment = Environment(
loader=loader,
autoescape=select_autoescape(),
enable_async=self.config.TEMPLATING_ENABLE_ASYNC,
)
if not hasattr(bootstrap, "templating"):
bootstrap.templating = Templating(
environment=bootstrap.environment, config=self.config
)
bootstrap.templating.environment.globals["url_for"] = self.app.url_for
def label(self):
return f"jinja2=={__version__}"
def _add_template_paths_to_reloader(
self, path: Union[str, os.PathLike, Sequence[Union[str, os.PathLike]]]
) -> None:
if not isinstance(path, abc.Iterable) or isinstance(path, str):
path = [path]
for item in path:
self.app.state.reload_dirs.add(Path(item))