Skip to content

Commit

Permalink
Support raw tags in lambda.
Browse files Browse the repository at this point in the history
  • Loading branch information
fuktommy authored and cbroglie committed Jul 12, 2022
1 parent c1e7de1 commit 5229524
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion mustache.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,11 @@ func getElementText(element interface{}, buf io.Writer) error {
case *textElement:
fmt.Fprintf(buf, "%s", elem.text)
case *varElement:
fmt.Fprintf(buf, "{{%s}}", elem.name)
if elem.raw {
fmt.Fprintf(buf, "{{{%s}}}", elem.name)
} else {
fmt.Fprintf(buf, "{{%s}}", elem.name)
}
case *sectionElement:
if elem.inverted {
fmt.Fprintf(buf, "{{^%s}}", elem.name)
Expand Down
22 changes: 22 additions & 0 deletions mustache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,28 @@ func TestLambdaStruct(t *testing.T) {
}
}

func TestLambdaRawTag(t *testing.T) {
tmpl := `{{#Lambda}}Hello {{{Name}}}.{{/Lambda}}`
data := struct {
Name string
Lambda LambdaFunc
}{
Name: "<br>",
Lambda: func(text string, render RenderFunc) (string, error) {
return render(text)
},
}

output, err := Render(tmpl, data)
if err != nil {
t.Fatal(err)
}
expect := "Hello <br>."
if output != expect {
t.Fatalf("TestLambdaStruct expected %q got %q", expect, output)
}
}

func TestLambdaError(t *testing.T) {
tmpl := `{{#lambda}}{{/lambda}}`
data := map[string]interface{}{
Expand Down

0 comments on commit 5229524

Please sign in to comment.