The templates.py module#

Summary#

validate_template

Raise ValueError if any string in required is absent from template.

build_viewer_html_glb

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 ValueError if any string in required is absent from template.

Parameters:
templatestr

Template source text to validate.

requiredlist[str]

Strings that must all appear verbatim in template.

Raises:
ValueError

If 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 with json.dumps-encoded values so that special characters are escaped automatically.

Parameters:
glb_b64str

Base64-encoded GLB binary.

model_namestr

Display name shown in the viewer (replaces __MODEL_NAME_JSON__).

template_pathPath | None, default: None

Path to a custom HTML template. When None, the built-in glb_template.html is used. See the Custom HTML templates section of the user guide for the required placeholder contract.

Raises:
FileNotFoundError

If template_path is given but the file does not exist.

ValueError

If the template is missing one or both required placeholders.