Extending Auditorium
Each recipe below says where the new piece goes, which registry lists it, and
which test holds it. The gates are make test, make lint and make docs;
CI runs them on every pull request, and the book's own gate, make book-check, builds this book with every block executed.
A check rule#
A rule is a name in the registry, a function that yields findings, a fixture project that breaks it, and a help page that shows it broken and fixed. Every rule has all four:
from pathlib import Path from auditorium.check import RULES rules = set(RULES) fixtures = {p.name for p in Path("../tests/rules").iterdir() if p.is_dir()} pages = {p.stem for p in Path("../auditorium/help/rules").glob("*.md")} print(len(rules), "rules;", "fixtures for all:", rules == fixtures, "; help pages for all:", rules == pages)
26 rules; fixtures for all: True ; help pages for all: True
- Add a
Rule(name, group, level, catches)to_RULESinauditorium/check/__init__.py.groupis the pass that runs it:structurereads the files and starts no browser;layoutruns in Chromium. - Write the function. A structure rule takes the loaded
Projectand yieldsfinding(rule, file, line, message, fix); list it inSTRUCTUREincheck/structure.py. A layout rule measures incheck/audit.jsand is turned into findings incheck/layout.py. - Add
tests/rules/<name>/index.html, a project that breaks this rule;tests/test_check.pyruns every fixture and expects its rule. - Write
auditorium/help/rules/<name>.mdwith a broken and a fixed snippet;auditorium help rule <name>prints it, and the help tests run the snippets.
Write the message as what was measured against what, and the fix as an edit in the file's own terms. The reader is often a small model that will make exactly the edit you name.
A motion#
Entrances, exits, idles, emphases, ambients and grades are tables in
auditorium/static/auditorium.js (ENTRANCES, IDLES, EMPHASES,
AMBIENTS, GRADES). The check reads the names from the same tables, so a
new motion is valid as soon as it is in one:
from auditorium.check import vocab print("entrances:", vocab.entrances()) print("idles:", vocab.idles()) print("layouts:", vocab.layouts())
entrances: ['fade', 'rise', 'pop', 'flip', 'grow', 'draw', 'words', 'count'] idles: ['float', 'tilt', 'pulse', 'ken-burns'] layouts: ['title', 'statement', 'cards', 'stats', 'columns', 'figure', 'logos', 'photo', 'table', 'chart']
The procedure, with its traps (opacity and transform as separate effects, DOM
changes only at build), is know-how/adding-a-motion.md in the repository.
A new motion also goes into examples/motion, and someone looks at its frames
before it is done: a passing suite says it moves, not that it reads.
A template#
A template is a folder under auditorium/templates/:
cd ../auditorium/templates/poster && find . -type f | sort
./assets/logo.svg ./example/assets/logo.svg ./example/index.html ./example/theme.css ./index.html ./template.toml ./theme.css
template.tomlholdssummary,forandformats;template listreads it, and the first format is the default.index.html,theme.cssandassets/are whattemplate newcopies, with every element to replace markeddata-placeholder.example/is the same project finished. It stays in the package, and the tests hold it to the check: the skeleton must fail on its placeholders only, and the example must pass with no errors.
tests/test_templates.py covers each of those, and the themes test checks
every bundled theme for contrast on your example.
A theme#
A theme is a :root block of variables in auditorium/themes/<name>.css, and
nothing else: a selector would reach into markup the templates and layouts
own, and break when they change. tests/test_themes.py fails a theme that has
a selector, misses the geometry palette, or fails WCAG AA on any template's
example. A theme that fails contrast on one example is dropped, not patched
for it.
sed -n '1,12p' ../auditorium/themes/dark.css
/* dark: near-black stage on a warm-black letterbox, off-white text, amber
accent, and code colours for a dark panel. */
:root {
--aud-letterbox-bg: #07080a;
--aud-slide-bg: #14171c;
--aud-fg: #e8e6e3;
--aud-muted: #9a958d;
--aud-accent: #f7c873;
--aud-rule: #2a2e36;
--aud-code-bg: #1c2026;
--aud-code-keyword: #ff7b72;
--aud-code-literal: #79c0ff;
An image provider#
generate: entries in assets.yaml ask an image provider, a plugin
registered under the auditorium.image_providers entry point group:
[project.entry-points."auditorium.image_providers"] flat = "my_package:generate"
The function takes the prompt, the size, the seed and the format, and returns the image's bytes. This one paints a flat gradient; the block registers it by hand, where an installed package would register it through the entry point:
import io from pathlib import Path from PIL import Image import auditorium.assets as assets def generate(prompt, *, size, seed, format): image = Image.linear_gradient("L").resize(size).convert("RGB") out = io.BytesIO() image.save(out, format="PNG" if format == "png" else "JPEG") return out.getvalue() assets.providers = lambda: {"flat": generate} project = Path("build/ext/hero") (project / "assets").mkdir(parents=True, exist_ok=True) (project / "index.html").write_text('<main class="aud" data-format="square"><section data-beat="a"><img src="assets/hero.png"></section></main>') (project / "assets.yaml").write_text("assets/hero.png: {generate: a soft gradient, size: [640, 360], seed: 1, provider: flat}\n") for outcome in assets.resolve(project): print(outcome.as_dict()) print(Image.open(project / "assets/hero.png").size)
{'key': 'assets/hero.png', 'kind': 'generate', 'status': 'resolved', 'detail': ''}
(640, 360)
Use a generated image for a backdrop or an illustration no file gives you, never for a logo, a chart or text: a diffusion model draws something like it, not it.
The book#
This book lives in docs/: docs/scriptorium.yaml lists the chapters in
docs/chapters/, and docs/shots.py takes the screenshots. make book
builds the site and the PDF, with the gallery, into docs/site/; make book-check also fails on any block that failed, on a file under
docs/examples/ no chapter tangles, and on a CLI command the book never
names. The examples in docs/examples/ are tangled from the chapters: edit
the chapter, never the file.