The templates.py module#
Summary#
Raise |
|
Build a self-contained HTML viewer that renders a base64-encoded GLB. |
Description#
HTML template rendering helpers for web viewer export.
Module detail#
- templates.validate_template(template: str, required: list[str]) None#
Raise
ValueErrorif any string in required is absent from template.- Parameters:
- Raises:
ValueErrorIf one or more required strings are absent.
- templates.build_viewer_html_glb(glb_b64: str, model_name: str, template_path: pathlib.Path | None = None) str#
Build a self-contained HTML viewer that renders a base64-encoded GLB.
The template is validated with
validate_template()before substitution. Both__GLB_B64_JSON__and__MODEL_NAME_JSON__must appear verbatim in the template source; they are replaced withjson.dumps-encoded values so that special characters are escaped automatically.- Parameters:
- glb_b64
str Base64-encoded GLB binary.
- model_name
str Display name shown in the viewer (replaces
__MODEL_NAME_JSON__).- template_path
Path|None, default:None Path to a custom HTML template. When
None, the built-inglb_template.htmlis used. See the Custom HTML templates section of the user guide for the required placeholder contract.
- glb_b64
- Raises:
FileNotFoundErrorIf template_path is given but the file does not exist.
ValueErrorIf the template is missing one or both required placeholders.