Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'tpl/compare/compare.go')
-rw-r--r--tpl/compare/compare.go43
1 files changed, 33 insertions, 10 deletions
diff --git a/tpl/compare/compare.go b/tpl/compare/compare.go
index 65228da99..b228040cd 100644
--- a/tpl/compare/compare.go
+++ b/tpl/compare/compare.go
@@ -88,11 +88,12 @@ func (*Namespace) Default(dflt interface{}, given ...interface{}) (interface{},
// Eq returns the boolean truth of arg1 == arg2.
func (*Namespace) Eq(x, y interface{}) bool {
- // hugolib.Page implements compare.Eqer to make Page and PageOutput comparable.
- if e1, ok := x.(compare.Eqer); ok {
- if e2, ok := y.(compare.Eqer); ok {
- return e1.Eq(e2)
- }
+ if e, ok := x.(compare.Eqer); ok {
+ return e.Eq(y)
+ }
+
+ if e, ok := y.(compare.Eqer); ok {
+ return e.Eq(x)
}
normalize := func(v interface{}) interface{} {
@@ -120,25 +121,25 @@ func (n *Namespace) Ne(x, y interface{}) bool {
// Ge returns the boolean truth of arg1 >= arg2.
func (n *Namespace) Ge(a, b interface{}) bool {
- left, right := n.compareGetFloat(a, b)
+ left, right := n.compareGet(a, b)
return left >= right
}
// Gt returns the boolean truth of arg1 > arg2.
func (n *Namespace) Gt(a, b interface{}) bool {
- left, right := n.compareGetFloat(a, b)
+ left, right := n.compareGet(a, b)
return left > right
}
// Le returns the boolean truth of arg1 <= arg2.
func (n *Namespace) Le(a, b interface{}) bool {
- left, right := n.compareGetFloat(a, b)
+ left, right := n.compareGet(a, b)
return left <= right
}
// Lt returns the boolean truth of arg1 < arg2.
func (n *Namespace) Lt(a, b interface{}) bool {
- left, right := n.compareGetFloat(a, b)
+ left, right := n.compareGet(a, b)
return left < right
}
@@ -151,7 +152,29 @@ func (n *Namespace) Conditional(condition bool, a, b interface{}) interface{} {
return b
}
-func (*Namespace) compareGetFloat(a interface{}, b interface{}) (float64, float64) {
+func (*Namespace) compareGet(a interface{}, b interface{}) (float64, float64) {
+ if ac, ok := a.(compare.Comparer); ok {
+ c := ac.Compare(b)
+ if c < 0 {
+ return 1, 0
+ } else if c == 0 {
+ return 0, 0
+ } else {
+ return 0, 1
+ }
+ }
+
+ if bc, ok := b.(compare.Comparer); ok {
+ c := bc.Compare(a)
+ if c < 0 {
+ return 0, 1
+ } else if c == 0 {
+ return 0, 0
+ } else {
+ return 1, 0
+ }
+ }
+
var left, right float64
var leftStr, rightStr *string
av := reflect.ValueOf(a)