1
0
mirror of https://github.com/danog/liquid.git synced 2024-11-26 21:34:44 +01:00

Update remaining public API to return SourceError

This commit is contained in:
Oliver Steele 2017-07-10 11:52:14 -04:00
parent 342a8b3e81
commit 378c0b207e
3 changed files with 7 additions and 5 deletions

View File

@ -71,12 +71,12 @@ func (e *Engine) RegisterTag(name string, td Renderer) {
}
// ParseTemplate creates a new Template using the engine configuration.
func (e *Engine) ParseTemplate(source []byte) (*Template, error) {
func (e *Engine) ParseTemplate(source []byte) (*Template, SourceError) {
return newTemplate(&e.cfg, source)
}
// ParseAndRender parses and then renders the template.
func (e *Engine) ParseAndRender(source []byte, b Bindings) ([]byte, error) {
func (e *Engine) ParseAndRender(source []byte, b Bindings) ([]byte, SourceError) {
tpl, err := e.ParseTemplate(source)
if err != nil {
return nil, err
@ -85,7 +85,7 @@ func (e *Engine) ParseAndRender(source []byte, b Bindings) ([]byte, error) {
}
// ParseAndRenderString is a convenience wrapper for ParseAndRender, that takes string input and returns a string.
func (e *Engine) ParseAndRenderString(source string, b Bindings) (string, error) {
func (e *Engine) ParseAndRenderString(source string, b Bindings) (string, SourceError) {
bs, err := e.ParseAndRender([]byte(source), b)
if err != nil {
return "", err

View File

@ -39,6 +39,8 @@ type SourceError interface {
// are likely to change.
func IsTemplateError(err error) bool {
switch err.(type) {
// TODO some of these clauses, or maybe the entire function, is unnecessary
// now that interface calls return SourceError
case evaluator.TypeError:
return true
case expression.InterpreterError:

View File

@ -23,7 +23,7 @@ func newTemplate(cfg *render.Config, source []byte) (*Template, SourceError) {
}
// Render executes the template with the specified variable bindings.
func (t *Template) Render(vars Bindings) ([]byte, error) {
func (t *Template) Render(vars Bindings) ([]byte, SourceError) {
buf := new(bytes.Buffer)
err := render.Render(t.root, buf, vars, *t.config)
if err != nil {
@ -33,7 +33,7 @@ func (t *Template) Render(vars Bindings) ([]byte, error) {
}
// RenderString is a convenience wrapper for Render, that has string input and output.
func (t *Template) RenderString(b Bindings) (string, error) {
func (t *Template) RenderString(b Bindings) (string, SourceError) {
bs, err := t.Render(b)
if err != nil {
return "", err