Skip to content

Commit

Permalink
Support missing variables at any depth
Browse files Browse the repository at this point in the history
  • Loading branch information
iwamot committed Apr 25, 2020
1 parent 7b1d416 commit e039f8c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion mustache.go
Expand Up @@ -602,7 +602,9 @@ func renderSection(section *sectionElement, contextChain []interface{}, buf io.W
for _, ctx := range contexts {
chain2[0] = ctx
for _, elem := range section.elems {
renderElement(elem, chain2, buf)
if err := renderElement(elem, chain2, buf); err != nil {
return err
}
}
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion mustache_test.go
Expand Up @@ -184,7 +184,6 @@ var tests = []Test{
{`"{{{person.name}}}" == "{{#person}}{{{name}}}{{/person}}"`, map[string]interface{}{"person": map[string]string{"name": "Joe"}}, `"Joe" == "Joe"`, nil},
{`"{{a.b.c.d.e.name}}" == "Phil"`, map[string]interface{}{"a": map[string]interface{}{"b": map[string]interface{}{"c": map[string]interface{}{"d": map[string]interface{}{"e": map[string]string{"name": "Phil"}}}}}}, `"Phil" == "Phil"`, nil},
{`"{{#a}}{{b.c.d.e.name}}{{/a}}" == "Phil"`, map[string]interface{}{"a": map[string]interface{}{"b": map[string]interface{}{"c": map[string]interface{}{"d": map[string]interface{}{"e": map[string]string{"name": "Phil"}}}}}, "b": map[string]interface{}{"c": map[string]interface{}{"d": map[string]interface{}{"e": map[string]string{"name": "Wrong"}}}}}, `"Phil" == "Phil"`, nil},
{`{{#a}}{{b.c}}{{/a}}`, map[string]interface{}{"a": map[string]interface{}{"b": map[string]string{}}, "b": map[string]string{"c": "ERROR"}}, "", nil},
}

func TestBasic(t *testing.T) {
Expand Down Expand Up @@ -219,6 +218,7 @@ var missing = []Test{
//dotted names(dot notation)
{`"{{a.b.c}}" == ""`, map[string]interface{}{}, `"" == ""`, nil},
{`"{{a.b.c.name}}" == ""`, map[string]interface{}{"a": map[string]interface{}{"b": map[string]string{}}, "c": map[string]string{"name": "Jim"}}, `"" == ""`, nil},
{`{{#a}}{{b.c}}{{/a}}`, map[string]interface{}{"a": map[string]interface{}{"b": map[string]string{}}, "b": map[string]string{"c": "ERROR"}}, "", nil},
}

func TestMissing(t *testing.T) {
Expand Down

0 comments on commit e039f8c

Please sign in to comment.