Document template partials
This commit is contained in:
@@ -12,6 +12,7 @@ Tomorrow, and Hourly.
|
|||||||
The package embeds assets from:
|
The package embeds assets from:
|
||||||
|
|
||||||
- `internal/reporttemplate/templates/*.md.tmpl`
|
- `internal/reporttemplate/templates/*.md.tmpl`
|
||||||
|
- `internal/reporttemplate/templates/partials/*.md.tmpl`
|
||||||
- `internal/reporttemplate/schemas/*.schema.json`
|
- `internal/reporttemplate/schemas/*.schema.json`
|
||||||
|
|
||||||
Generated-text prompt source files live under
|
Generated-text prompt source files live under
|
||||||
@@ -73,6 +74,12 @@ template and renders from `generatedtext.DailyRenderContext`.
|
|||||||
Templates use `text/template` with `missingkey=error`, so missing context fields
|
Templates use `text/template` with `missingkey=error`, so missing context fields
|
||||||
fail rendering instead of producing incomplete Markdown.
|
fail rendering instead of producing incomplete Markdown.
|
||||||
|
|
||||||
|
Daily and Tomorrow call the shared `daypart_forecast` partial. Today calls
|
||||||
|
`today_daypart_forecast` so it can omit elapsed or missing dayparts. Daily,
|
||||||
|
Today, and Tomorrow call the shared `precipitation_timing` partial. Partial
|
||||||
|
files are parsed with each top-level template at render time and receive the
|
||||||
|
same typed render context as the caller.
|
||||||
|
|
||||||
## Schema Contract
|
## Schema Contract
|
||||||
|
|
||||||
The GeneratedText schemas describe the structured prose Scriptorium is expected
|
The GeneratedText schemas describe the structured prose Scriptorium is expected
|
||||||
@@ -92,6 +99,7 @@ slots consumed by the template.
|
|||||||
- Unknown template IDs return actionable lookup errors.
|
- Unknown template IDs return actionable lookup errors.
|
||||||
- Unknown schema IDs return actionable lookup errors.
|
- Unknown schema IDs return actionable lookup errors.
|
||||||
- Template parse errors include the template ID.
|
- Template parse errors include the template ID.
|
||||||
|
- Partial read or parse errors include the partial path.
|
||||||
- Template execution errors include the template ID and usually identify the
|
- Template execution errors include the template ID and usually identify the
|
||||||
missing context field.
|
missing context field.
|
||||||
|
|
||||||
@@ -107,6 +115,7 @@ Inspect:
|
|||||||
## Invariants
|
## Invariants
|
||||||
|
|
||||||
- Embedded templates and schemas live as separate files, not inline Go strings.
|
- Embedded templates and schemas live as separate files, not inline Go strings.
|
||||||
|
- Shared Markdown partials live under `templates/partials/`.
|
||||||
- Report definitions select templates by ID.
|
- Report definitions select templates by ID.
|
||||||
- Templates render from curated render contexts, not raw data packages.
|
- Templates render from curated render contexts, not raw data packages.
|
||||||
- GeneratedText schemas describe LLM prose slots, not deterministic weather
|
- GeneratedText schemas describe LLM prose slots, not deterministic weather
|
||||||
|
|||||||
@@ -13,6 +13,12 @@ Templates are Go `text/template` files. The current implemented templates are:
|
|||||||
- `internal/reporttemplate/templates/tomorrow.md.tmpl`
|
- `internal/reporttemplate/templates/tomorrow.md.tmpl`
|
||||||
- `internal/reporttemplate/templates/hourly.md.tmpl`
|
- `internal/reporttemplate/templates/hourly.md.tmpl`
|
||||||
|
|
||||||
|
Shared named partials live under `internal/reporttemplate/templates/partials/`:
|
||||||
|
|
||||||
|
- `daypart_forecast.md.tmpl`, used by Daily and Tomorrow
|
||||||
|
- `today_daypart_forecast.md.tmpl`, used by Today
|
||||||
|
- `precipitation_timing.md.tmpl`, used by Daily, Today, and Tomorrow
|
||||||
|
|
||||||
Templates are rendered from structured contexts such as `DailyRenderContext`,
|
Templates are rendered from structured contexts such as `DailyRenderContext`,
|
||||||
`TodayRenderContext`, `TomorrowRenderContext`, and `HourlyRenderContext`.
|
`TodayRenderContext`, `TomorrowRenderContext`, and `HourlyRenderContext`.
|
||||||
Weather data collection, derivation, module execution, generated text
|
Weather data collection, derivation, module execution, generated text
|
||||||
@@ -27,6 +33,9 @@ validation, and artifact paths are handled before template rendering.
|
|||||||
templates.
|
templates.
|
||||||
- Missing template keys are errors. A misspelled variable will fail rendering.
|
- Missing template keys are errors. A misspelled variable will fail rendering.
|
||||||
- No custom template functions are currently registered.
|
- No custom template functions are currently registered.
|
||||||
|
- Named partials are invoked with `{{ template "name" . }}`. Pass the current
|
||||||
|
render context (`.`) unless the partial is intentionally designed for a
|
||||||
|
narrower value.
|
||||||
- Optional module stanzas are pointers and should be guarded with
|
- Optional module stanzas are pointers and should be guarded with
|
||||||
`{{ with .Modules.WeatherStory }}...{{ end }}`.
|
`{{ with .Modules.WeatherStory }}...{{ end }}`.
|
||||||
- Slices can be rendered with `{{ range .Items }}...{{ else }}...{{ end }}`.
|
- Slices can be rendered with `{{ range .Items }}...{{ else }}...{{ end }}`.
|
||||||
@@ -131,6 +140,8 @@ Daily generated text uses `.GeneratedText.Summary`,
|
|||||||
`.GeneratedText.Confidence`. Forecast discussion is a slice of paragraphs and
|
`.GeneratedText.Confidence`. Forecast discussion is a slice of paragraphs and
|
||||||
should be rendered with `range`.
|
should be rendered with `range`.
|
||||||
|
|
||||||
|
Daily uses the shared `daypart_forecast` and `precipitation_timing` partials.
|
||||||
|
|
||||||
Daily uses template ID `daily`, generated-text schema ID `daily`, and prompt
|
Daily uses template ID `daily`, generated-text schema ID `daily`, and prompt
|
||||||
source `internal/reporttemplate/prompts/daily.generated_text.md`.
|
source `internal/reporttemplate/prompts/daily.generated_text.md`.
|
||||||
|
|
||||||
@@ -162,6 +173,10 @@ Today generated text uses `.GeneratedText.Summary`,
|
|||||||
`.GeneratedText.Confidence`. Forecast discussion is a slice of paragraphs and
|
`.GeneratedText.Confidence`. Forecast discussion is a slice of paragraphs and
|
||||||
should be rendered with `range`.
|
should be rendered with `range`.
|
||||||
|
|
||||||
|
Today uses the `today_daypart_forecast` partial so elapsed or missing dayparts
|
||||||
|
can be omitted while Daily and Tomorrow keep their fallback row. It also uses
|
||||||
|
the shared `precipitation_timing` partial.
|
||||||
|
|
||||||
Today uses template ID `today`, generated-text schema ID `today`, and prompt
|
Today uses template ID `today`, generated-text schema ID `today`, and prompt
|
||||||
source `internal/reporttemplate/prompts/today.generated_text.md`.
|
source `internal/reporttemplate/prompts/today.generated_text.md`.
|
||||||
|
|
||||||
@@ -282,6 +297,10 @@ Daily, Today, and Tomorrow templates should use `.Modules.Dayparts` for
|
|||||||
ordered daypart rendering. Each item has `Key` and `Summary`; `Summary` is a
|
ordered daypart rendering. Each item has `Key` and `Summary`; `Summary` is a
|
||||||
rich `briefing.DerivedDaypartSummaryModule`.
|
rich `briefing.DerivedDaypartSummaryModule`.
|
||||||
|
|
||||||
|
The shared daypart partials render from these same `.Modules.Dayparts` values.
|
||||||
|
Edit `daypart_forecast.md.tmpl` for common Daily/Tomorrow wording, and edit
|
||||||
|
`today_daypart_forecast.md.tmpl` for Today-specific omission behavior.
|
||||||
|
|
||||||
Common rich daypart fields:
|
Common rich daypart fields:
|
||||||
|
|
||||||
| Variable | Type | Description |
|
| Variable | Type | Description |
|
||||||
|
|||||||
Reference in New Issue
Block a user