# ══════════════════════════════════════════════════════════════════════════
# ___ ___ ___ _ _ ___
# / _ \ / __|_ ) | | /_\ | _ )
# | (_) | (__ / / | |__ / _ \| _ \
# \__\_\\___/___| |____/_/ \_\___/
#
# QC2 @ CHALMERS CALIBRATION TOOLKIT
# (c) 2026 Chalmers University of Technology and Project Contributors
# ──────────────────────────────────────────────────────────────────────────
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ──────────────────────────────────────────────────────────────────────────
# CONTRIBUTORS list:
#
# Axel Andersson, axean@chalmers.se
# ══════════════════════════════════════════════════════════════════════════
"""Single entry point for the front-end source files.
All non-Python sources live under ``rendering/<language>/`` — ``html/``,
``css/`` and ``js/``. ``load("replot.html")`` resolves the language subdir
from the file extension, so no caller spells out a path and the directory
layout has exactly one owner: this module.
The Python assembles a page by loading a shell template and substituting the
``@@MARKER@@`` placeholders with other loaded fragments; the source files
never reference each other by path.
"""
from pathlib import Path
_RENDERING_DIR = Path(__file__).parent
# Map a file extension to the language subdirectory that owns it.
_SUBDIR_BY_SUFFIX = {".html": "html", ".css": "css", ".js": "js"}
[docs]
def template_path(name: str) -> Path:
"""Resolve a template file name to its on-disk path under the right dir."""
subdir = _SUBDIR_BY_SUFFIX.get(Path(name).suffix)
if subdir is None:
raise ValueError(
f"unknown template language for {name!r}; "
f"expected one of {sorted(_SUBDIR_BY_SUFFIX)}"
)
return _RENDERING_DIR / subdir / name
[docs]
def load(name: str) -> str:
"""Read a template file's text by name (e.g. ``load('replot.css')``)."""
return template_path(name).read_text(encoding="utf-8")