Expose template options

This commit is contained in:
2026-05-27 08:26:14 +02:00
parent 59c8e407e9
commit 89508b3c03
7 changed files with 236 additions and 0 deletions
+68
View File
@@ -710,6 +710,74 @@ providers:
}
}
func TestWikiTemplateFactsProviderRendersYAMLDeclaredFactRows(t *testing.T) {
root := t.TempDir()
dataPath := filepath.Join(root, "data.yaml")
writeFile(t, dataPath, `
providers:
FeatFacts:
source: facts
facts:
rows:
- label: Prerequisites
value: "{{feat_prerequisites()}}"
- label: Minimum Attack Bonus
value: "{{MINATTACKBONUS}}"
- label: Armor Check Penalty
value: "{{yes_no(ArmorCheckPenalty)}}"
- label: Missing Optional
value: "{{MissingField}}"
`+"\n")
providers, err := loadWikiDataProviders(dataPath)
if err != nil {
t.Fatalf("load data providers: %v", err)
}
ctx := testWikiTableContext(t, "")
ctx.wikiDataPath = dataPath
ctx.wikiDataProviders = providers
ctx.featRows["feat:power_attack"] = map[string]any{"FEAT": map[string]any{"tlk": map[string]any{"text": "Power Attack"}}}
ctx.featIDToKey[28] = "feat:power_attack"
ctx.skillRows = map[string]map[string]any{"skills:athletics": {"Name": map[string]any{"tlk": map[string]any{"text": "Athletics"}}}}
ctx.skillIDToKey = map[int]string{3: "skills:athletics"}
page := wikiTemplatePage{
PageID: "feat:cleave",
Category: "feat",
Key: "feat:cleave",
Title: "Cleave",
Row: map[string]any{
"MINSTR": "13",
"PREREQFEAT1": 28,
"REQSKILL": 3,
"ReqSkillMinRanks": "4",
"MINATTACKBONUS": "2",
"ArmorCheckPenalty": "1",
},
}
got, err := ctx.renderWikiTemplateString("feat.html", `<table class="wiki-facts">
<tbody>
{{#each FeatFacts}}
<tr><th scope="row">{{Label}}</th><td>{{Value|wiki}}</td></tr>
{{/each}}
</tbody>
</table>`, page)
if err != nil {
t.Fatalf("render template: %v", err)
}
for _, expected := range []string{
`<th scope="row">Prerequisites</th><td>Str 13, [[Feats/Power_Attack|Power Attack]], [[Skills/Athletics|Athletics]] 4 ranks</td>`,
`<th scope="row">Minimum Attack Bonus</th><td>2</td>`,
`<th scope="row">Armor Check Penalty</th><td>Yes</td>`,
} {
if !strings.Contains(got, expected) {
t.Fatalf("expected %q in rendered facts:\n%s", expected, got)
}
}
if strings.Contains(got, "Missing Optional") {
t.Fatalf("expected empty optional fact to be omitted:\n%s", got)
}
}
func TestWikiTemplateClassProgressionProviderUsesDefaultNWNAttackSequences(t *testing.T) {
ctx := &wikiContext{
wikiDataPath: "test-data.yaml",