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"
"github.com/osteele/liquid/expression"
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.
2017-07-04 17:41:45 +02:00
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
Filename ( ) string
LineNumber ( ) int
}
2017-07-10 05:15:05 +02:00
// IsTemplateError returns true iff the error represents an error in the template
2017-07-10 13:51:51 +02:00
// syntax or execution. It is used to distinguish errors in input values from errors in the Liquid implemtation, 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 ) {
2017-07-10 17:52:14 +02:00
// 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
case expression . InterpreterError :
return true
case expression . ParseError :
return true
2017-07-07 11:41:37 +02:00
case parser . ParseError :
2017-07-06 14:59:10 +02:00
return true
2017-07-07 11:41:37 +02:00
case render . CompilationError :
2017-07-05 20:24:15 +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
}
}