Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 22a98f022b |
@ -10,6 +10,14 @@ https://pypi.org/project/template-nest/.
|
||||
|
||||
* News
|
||||
|
||||
** v0.1.6 - 2025-12-02
|
||||
|
||||
+ Treat empty hash as nil
|
||||
|
||||
Tom: I think that if go's behaviour is to insert an empty map when nil is
|
||||
returned as a templatenest.Hash, then we need to change the templatenest
|
||||
behaviour to regard an empty map as being nil.
|
||||
|
||||
** v0.1.5 - 2025-02-22
|
||||
|
||||
+ Handle all pointer types generically.
|
||||
|
||||
@ -364,10 +364,15 @@ func (nest *TemplateNest) renderSlice(toRender interface{}) (string, error) {
|
||||
}
|
||||
|
||||
func (nest *TemplateNest) renderHash(hash map[string]interface{}) (string, error) {
|
||||
// If the hash is completely empty, return an empty string.
|
||||
if len(hash) == 0 {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
tLabel, ok := hash[*nest.option.NameLabel]
|
||||
if !ok {
|
||||
return "", fmt.Errorf(
|
||||
"encountered hash with no name label (name label: `%s`)", nest.option.NameLabel,
|
||||
"encountered hash with no name label (name label: `%+v`)", nest.option.NameLabel,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -174,6 +174,19 @@ func TestRenderNoNameLabel(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderEmptyHash(t *testing.T) {
|
||||
nest, err := templatenest.New(templatenest.Option{TemplateDir: "templates"})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to initialize TemplateNest: %+v", err)
|
||||
}
|
||||
|
||||
page := templatenest.Hash{}
|
||||
|
||||
render, err := nest.Render(page)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "", render)
|
||||
}
|
||||
|
||||
func TestRenderSimplePageArrays(t *testing.T) {
|
||||
nest, err := templatenest.New(templatenest.Option{
|
||||
TemplateDir: "templates",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user