forked from osteele/liquid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilders.go
45 lines (39 loc) · 1.16 KB
/
builders.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package expressions
import (
"github.com/osteele/liquid/values"
)
func makeRangeExpr(startFn, endFn func(Context) values.Value) func(Context) values.Value {
return func(ctx Context) values.Value {
a := startFn(ctx).Int()
b := endFn(ctx).Int()
return values.ValueOf(values.NewRange(a, b))
}
}
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)))
}
}
func makeFilter(fn valueFn, name string, args []valueFn) valueFn {
return func(ctx Context) values.Value {
result, err := ctx.ApplyFilter(name, fn, args)
if err != nil {
panic(FilterError{
FilterName: name,
Err: err,
})
}
return values.ValueOf(result)
}
}
func makeIndexExpr(sequenceFn, indexFn func(Context) values.Value) func(Context) values.Value {
return func(ctx Context) values.Value {
return sequenceFn(ctx).IndexValue(indexFn(ctx))
}
}
func makeObjectPropertyExpr(objFn func(Context) values.Value, name string) func(Context) values.Value {
index := values.ValueOf(name)
return func(ctx Context) values.Value {
return objFn(ctx).PropertyValue(index)
}
}