mirror of
https://github.com/danog/liquid.git
synced 2024-12-02 14:27:46 +01:00
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package expressions
|
|
|
|
import (
|
|
"reflect"
|
|
|
|
"github.com/osteele/liquid/evaluator"
|
|
)
|
|
|
|
func makeRangeExpr(startFn, endFn func(Context) interface{}) func(Context) interface{} {
|
|
return func(ctx Context) interface{} {
|
|
var proto int
|
|
b := evaluator.MustConvert(startFn(ctx), reflect.TypeOf(proto))
|
|
e := evaluator.MustConvert(endFn(ctx), reflect.TypeOf(proto))
|
|
return evaluator.NewRange(b.(int), e.(int))
|
|
}
|
|
}
|
|
|
|
func makeContainsExpr(e1, e2 func(Context) interface{}) func(Context) interface{} {
|
|
return func(ctx Context) interface{} {
|
|
s, ok := e2((ctx)).(string)
|
|
if !ok {
|
|
return false
|
|
}
|
|
return evaluator.ContainsString(e1(ctx), s)
|
|
}
|
|
}
|
|
|
|
func makeFilter(fn valueFn, name string, args []valueFn) valueFn {
|
|
return func(ctx Context) interface{} {
|
|
return ctx.ApplyFilter(name, fn, args)
|
|
}
|
|
}
|
|
|
|
func makeIndexExpr(sequenceFn, indexFn func(Context) interface{}) func(Context) interface{} {
|
|
return func(ctx Context) interface{} {
|
|
return evaluator.Index(sequenceFn(ctx), indexFn(ctx))
|
|
}
|
|
}
|
|
|
|
func makeObjectPropertyExpr(objFn func(Context) interface{}, name string) func(Context) interface{} {
|
|
return func(ctx Context) interface{} {
|
|
return evaluator.ObjectProperty(objFn(ctx), name)
|
|
}
|
|
}
|