1
0
mirror of https://github.com/danog/liquid.git synced 2024-11-30 08:18:59 +01:00
liquid/liquid.go

60 lines
2.0 KiB
Go
Raw Normal View History

2017-06-30 17:20:32 +02:00
/*
2017-07-10 05:15:05 +02:00
Package liquid is a pure Go implementation of Shopify Liquid templates, developed for use in https://github.com/osteele/gojekyll.
2017-06-30 17:20:32 +02:00
See the project README https://github.com/osteele/liquid for additional information and implementation status.
2017-07-05 20:24:15 +02:00
2017-07-10 13:51:51 +02:00
The liquid package itself is versioned in gopkg.in. Subpackages have no compatibility guarantees. Except where specifically documented, the public entities of subpackages are intended only for use by the liquid package and its subpackages.
2017-06-30 17:20:32 +02:00
*/
package liquid
import (
2017-07-05 20:24:15 +02:00
"github.com/osteele/liquid/evaluator"
2017-07-14 02:18:23 +02:00
"github.com/osteele/liquid/expressions"
2017-07-07 11:41:37 +02:00
"github.com/osteele/liquid/parser"
2017-07-04 17:03:18 +02:00
"github.com/osteele/liquid/render"
2017-06-30 17:20:32 +02:00
)
2017-07-03 18:00:43 +02:00
// Bindings is a map of variable names to values.
2017-07-10 13:51:51 +02:00
//
// Clients need not use this type. It is used solely for documentation. Callers can use unconverted instances
// of map[interface] itself as argument values to functions declared with this parameter type.
2017-07-03 03:17:04 +02:00
type Bindings map[string]interface{}
2017-06-30 17:20:32 +02:00
2017-07-04 22:48:38 +02:00
// A Renderer returns the rendered string for a block.
type Renderer func(render.Context) (string, error)
2017-07-05 20:24:15 +02:00
2017-07-10 17:49:14 +02:00
// SourceError records an error with a source location and optional cause.
type SourceError interface {
error
Cause() error
2017-07-12 13:12:14 +02:00
Path() string
2017-07-10 17:49:14 +02:00
LineNumber() int
}
2017-07-10 05:15:05 +02:00
// IsTemplateError returns true iff the error represents an error in the template
// syntax or execution. It is used to distinguish errors in input values from errors in the Liquid implementation, or the implementation of tags and filters, themselves.
2017-07-05 20:24:15 +02:00
//
2017-07-10 05:15:05 +02:00
// Use this function to avoid coding the specific types of subpackage errors, which
2017-07-05 20:24:15 +02:00
// 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
2017-07-05 20:24:15 +02:00
case evaluator.TypeError:
return true
2017-07-14 02:18:23 +02:00
case expressions.InterpreterError:
2017-07-05 20:24:15 +02:00
return true
2017-07-14 02:18:23 +02:00
case expressions.ParseError:
2017-07-05 20:24:15 +02:00
return true
case parser.Error:
2017-07-06 14:59:10 +02:00
return true
2017-07-06 01:33:24 +02:00
case render.Error:
return true
2017-07-10 17:49:14 +02:00
case SourceError:
return true
2017-07-05 20:24:15 +02:00
default:
2017-07-06 01:33:24 +02:00
return false
2017-07-05 20:24:15 +02:00
}
}