2017-07-28 00:11:37 +02:00
|
|
|
package values
|
2017-07-06 05:25:03 +02:00
|
|
|
|
2017-08-03 15:11:34 +02:00
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
)
|
2017-07-28 00:30:03 +02:00
|
|
|
|
2017-07-06 05:25:03 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
2017-07-21 22:26:04 +02:00
|
|
|
|
|
|
|
type dropWrapper struct {
|
|
|
|
d drop
|
|
|
|
v Value
|
2017-08-03 15:11:34 +02:00
|
|
|
sync.Once
|
2017-07-21 22:26:04 +02:00
|
|
|
}
|
|
|
|
|
2017-08-03 15:11:34 +02:00
|
|
|
func (w *dropWrapper) Resolve() Value {
|
|
|
|
w.Do(func() { w.v = ValueOf(w.d.ToLiquid()) })
|
2017-07-21 22:26:04 +02:00
|
|
|
return w.v
|
|
|
|
}
|
|
|
|
|
2017-08-03 15:11:34 +02:00
|
|
|
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() }
|