forked from osteele/liquid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
drop.go
39 lines (33 loc) · 1.12 KB
/
drop.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
package values
import (
"sync"
)
type drop interface {
ToLiquid() interface{}
}
// ToLiquid converts an object to Liquid, if it implements the Drop interface.
func ToLiquid(value interface{}) interface{} {
switch value := value.(type) {
case drop:
return value.ToLiquid()
default:
return value
}
}
type dropWrapper struct {
d drop
v Value
sync.Once
}
func (w *dropWrapper) Resolve() Value {
w.Do(func() { w.v = ValueOf(w.d.ToLiquid()) })
return w.v
}
func (w *dropWrapper) Equal(o Value) bool { return w.Resolve().Equal(o) }
func (w *dropWrapper) Less(o Value) bool { return w.Resolve().Less(o) }
func (w *dropWrapper) IndexValue(i Value) Value { return w.Resolve().IndexValue(i) }
func (w *dropWrapper) Contains(o Value) bool { return w.Resolve().Contains(o) }
func (w *dropWrapper) Int() int { return w.Resolve().Int() }
func (w *dropWrapper) Interface() interface{} { return w.Resolve().Interface() }
func (w *dropWrapper) PropertyValue(k Value) Value { return w.Resolve().PropertyValue(k) }
func (w *dropWrapper) Test() bool { return w.Resolve().Test() }