1
0
mirror of https://github.com/danog/liquid.git synced 2024-11-26 23:04:38 +01:00
liquid/template.go

32 lines
647 B
Go
Raw Normal View History

2017-06-27 13:43:42 +02:00
package liquid
import (
"bytes"
2017-07-04 17:03:18 +02:00
"github.com/osteele/liquid/render"
2017-06-27 13:43:42 +02:00
)
2017-06-30 22:13:18 +02:00
type template struct {
2017-07-04 17:03:18 +02:00
ast render.ASTNode
2017-07-04 17:08:57 +02:00
settings render.Config
2017-06-30 22:13:18 +02:00
}
2017-06-29 02:49:38 +02:00
// Render executes the template within the bindings environment.
2017-07-03 03:17:04 +02:00
func (t *template) Render(b Bindings) ([]byte, error) {
2017-06-27 13:43:42 +02:00
buf := new(bytes.Buffer)
err := render.Render(t.ast, buf, b, t.settings)
2017-06-27 13:43:42 +02:00
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}
// RenderString is a convenience wrapper for Render, that has string input and output.
2017-07-03 03:17:04 +02:00
func (t *template) RenderString(b Bindings) (string, error) {
bs, err := t.Render(b)
2017-06-27 13:43:42 +02:00
if err != nil {
return "", err
}
2017-07-03 03:17:04 +02:00
return string(bs), nil
2017-06-27 13:43:42 +02:00
}