2017-07-14 02:18:23 +02:00
|
|
|
package expressions
|
2017-06-28 02:32:55 +02:00
|
|
|
|
|
|
|
import (
|
2017-07-28 00:11:37 +02:00
|
|
|
"github.com/osteele/liquid/values"
|
2017-06-28 02:32:55 +02:00
|
|
|
)
|
|
|
|
|
2017-07-28 00:11:37 +02:00
|
|
|
func makeRangeExpr(startFn, endFn func(Context) values.Value) func(Context) values.Value {
|
|
|
|
return func(ctx Context) values.Value {
|
2017-07-20 15:12:31 +02:00
|
|
|
a := startFn(ctx).Int()
|
|
|
|
b := endFn(ctx).Int()
|
2017-07-28 00:11:37 +02:00
|
|
|
return values.ValueOf(values.NewRange(a, b))
|
2017-07-13 20:58:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-28 00:11:37 +02:00
|
|
|
func makeContainsExpr(e1, e2 func(Context) values.Value) func(Context) values.Value {
|
|
|
|
return func(ctx Context) values.Value {
|
|
|
|
return values.ValueOf(e1(ctx).Contains(e2(ctx)))
|
2017-06-28 02:32:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-30 22:13:18 +02:00
|
|
|
func makeFilter(fn valueFn, name string, args []valueFn) valueFn {
|
2017-07-28 00:11:37 +02:00
|
|
|
return func(ctx Context) values.Value {
|
2017-07-16 19:47:06 +02:00
|
|
|
result, err := ctx.ApplyFilter(name, fn, args)
|
|
|
|
if err != nil {
|
2017-07-21 02:36:44 +02:00
|
|
|
panic(FilterError{
|
|
|
|
FilterName: name,
|
|
|
|
Err: err,
|
|
|
|
})
|
2017-07-16 19:47:06 +02:00
|
|
|
}
|
2017-07-28 00:11:37 +02:00
|
|
|
return values.ValueOf(result)
|
2017-06-30 22:13:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-28 00:11:37 +02:00
|
|
|
func makeIndexExpr(sequenceFn, indexFn func(Context) values.Value) func(Context) values.Value {
|
|
|
|
return func(ctx Context) values.Value {
|
2017-07-20 15:12:31 +02:00
|
|
|
return sequenceFn(ctx).IndexValue(indexFn(ctx))
|
2017-06-28 02:32:55 +02:00
|
|
|
}
|
|
|
|
}
|
2017-06-30 17:21:10 +02:00
|
|
|
|
2017-07-28 00:11:37 +02:00
|
|
|
func makeObjectPropertyExpr(objFn func(Context) values.Value, name string) func(Context) values.Value {
|
|
|
|
index := values.ValueOf(name)
|
|
|
|
return func(ctx Context) values.Value {
|
2017-07-20 15:12:31 +02:00
|
|
|
return objFn(ctx).PropertyValue(index)
|
2017-06-30 17:21:10 +02:00
|
|
|
}
|
|
|
|
}
|