57 lines
2.5 KiB
Markdown
57 lines
2.5 KiB
Markdown
# Report Template Internals
|
|
|
|
`internal/reporttemplate` embeds and renders the repository's native Markdown
|
|
templates. The current template IDs are `daily`, `today`, `tomorrow`, and
|
|
`hourly`. The template files, partials, and complete render-context field
|
|
reference are maintained in
|
|
[report templates](../templates.md).
|
|
|
|
## Assets and lookup
|
|
|
|
The package embeds top-level templates and shared partials. `Template` returns
|
|
the requested embedded template and fails with the requested ID when it is
|
|
unknown or unreadable.
|
|
|
|
Generated-text schemas and Promptkit definitions are owned by
|
|
`internal/promptassets`; report-template owns Markdown source only. Report
|
|
definitions select IDs, while [generated-text internals](generatedtext.md)
|
|
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 or complete fact bundles, and it must not reimplement weather
|
|
selection or generated-text validation. Context construction rejects
|
|
report-identity disagreements before template execution. Every generated-prose
|
|
insertion uses the `plainText` helper. It retains ordinary prose and paragraph
|
|
breaks but renders Markdown/HTML syntax, code indentation, and control
|
|
characters as safe text, so the repository templates remain the sole owners of
|
|
report structure.
|
|
|
|
## Boundaries and verification
|
|
|
|
This package does not collect weather data, build modules, validate generated
|
|
text, construct contexts, resolve report definitions, write state, execute
|
|
Promptkit, or upload reports. It produces Markdown bytes for application
|
|
orchestration to persist.
|
|
|
|
Focused tests cover template lookup, rendering, partial behavior, daypart
|
|
fallbacks, missing keys, and malformed context:
|
|
|
|
```sh
|
|
go test ./internal/reporttemplate
|
|
```
|
|
|
|
Embedded templates stay as separate files and shared fragments stay under the
|
|
partial directory. Generated-text schemas are embedded separately by
|
|
`internal/promptassets` and describe prose slots rather than deterministic
|
|
weather facts.
|