Files
weatherreporter/docs/internal/reporttemplate.md

2.2 KiB

Report Template Internals

internal/reporttemplate embeds and renders the repository's native Markdown templates and exposes their companion generated-text schemas. The current asset IDs are daily, today, tomorrow, and hourly. The template files, partials, and complete render-context field reference are maintained in report templates.

Assets and lookup

The package embeds top-level templates, shared partials, and JSON schemas from its asset directories. Template and Schema return the requested embedded asset and fail with the requested ID when it is unknown or unreadable.

Generated-text catalog handlers obtain schema bytes and template source through these APIs. Prompt source files are repository assets for prompt registration; they are not reporttemplate lookup assets. Report definitions select IDs, while generated-text internals verifies the supported schema/template pairing.

Rendering

Render loads the top-level template, creates a text/template with helper functions and missingkey=error, parses the template, parses every shared partial, and executes the result against the typed render context. This makes missing context fields, bad template syntax, unreadable partials, and execution failures actionable with template or partial context.

Top-level templates decide which shared partials they invoke. The current partials cover daypart forecast variants, alert digest, and precipitation timing. Template code receives curated typed contexts rather than raw data packages, and it must not reimplement weather selection or generated-text validation.

Boundaries and verification

This package does not collect weather data, build modules, validate generated text, construct contexts, resolve report definitions, write state, execute Scriptorium, or upload reports. It produces Markdown bytes for application orchestration to persist.

Focused tests cover asset lookup, schema availability, rendering, partial behavior, missing keys, and malformed context:

go test ./internal/reporttemplate

Embedded assets stay as separate files, shared fragments stay under the partial directory, and generated-text schemas describe prose slots rather than deterministic weather facts.