2017-04-30 17:33:19 +00:00
|
|
|
// Copyright 2017 The Hugo Authors. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package compare
|
|
|
|
|
|
|
|
import (
|
2023-02-25 08:24:59 +00:00
|
|
|
"context"
|
|
|
|
|
2017-06-13 16:42:45 +00:00
|
|
|
"github.com/gohugoio/hugo/deps"
|
2022-06-06 07:48:40 +00:00
|
|
|
"github.com/gohugoio/hugo/langs"
|
2017-06-13 16:42:45 +00:00
|
|
|
"github.com/gohugoio/hugo/tpl/internal"
|
2017-04-30 17:33:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const name = "compare"
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
f := func(d *deps.Deps) *internal.TemplateFuncsNamespace {
|
2023-01-04 17:24:36 +00:00
|
|
|
language := d.Conf.Language()
|
|
|
|
if language == nil {
|
2022-06-06 07:48:40 +00:00
|
|
|
panic("language must be set")
|
|
|
|
}
|
|
|
|
|
2023-01-04 17:24:36 +00:00
|
|
|
ctx := New(langs.GetLocation(language), false)
|
2017-04-30 17:33:19 +00:00
|
|
|
|
2017-05-01 16:40:34 +00:00
|
|
|
ns := &internal.TemplateFuncsNamespace{
|
2017-04-30 17:33:19 +00:00
|
|
|
Name: name,
|
2023-02-25 08:24:59 +00:00
|
|
|
Context: func(cctx context.Context, args ...any) (any, error) { return ctx, nil },
|
2017-04-30 17:33:19 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 16:40:34 +00:00
|
|
|
ns.AddMethodMapping(ctx.Default,
|
|
|
|
[]string{"default"},
|
|
|
|
[][2]string{
|
|
|
|
{`{{ "Hugo Rocks!" | default "Hugo Rules!" }}`, `Hugo Rocks!`},
|
|
|
|
{`{{ "" | default "Hugo Rules!" }}`, `Hugo Rules!`},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
ns.AddMethodMapping(ctx.Eq,
|
|
|
|
[]string{"eq"},
|
|
|
|
[][2]string{
|
2022-02-17 12:04:00 +00:00
|
|
|
{`{{ if eq .Section "blog" }}current-section{{ end }}`, `current-section`},
|
2017-05-01 16:40:34 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
ns.AddMethodMapping(ctx.Ge,
|
|
|
|
[]string{"ge"},
|
2018-02-22 08:15:12 +00:00
|
|
|
[][2]string{
|
2022-02-17 12:04:00 +00:00
|
|
|
{`{{ if ge hugo.Version "0.80" }}Reasonable new Hugo version!{{ end }}`, `Reasonable new Hugo version!`},
|
2018-02-22 08:15:12 +00:00
|
|
|
},
|
2017-05-01 16:40:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
ns.AddMethodMapping(ctx.Gt,
|
|
|
|
[]string{"gt"},
|
|
|
|
[][2]string{},
|
|
|
|
)
|
|
|
|
|
|
|
|
ns.AddMethodMapping(ctx.Le,
|
|
|
|
[]string{"le"},
|
|
|
|
[][2]string{},
|
|
|
|
)
|
|
|
|
|
|
|
|
ns.AddMethodMapping(ctx.Lt,
|
|
|
|
[]string{"lt"},
|
|
|
|
[][2]string{},
|
|
|
|
)
|
|
|
|
|
|
|
|
ns.AddMethodMapping(ctx.Ne,
|
|
|
|
[]string{"ne"},
|
|
|
|
[][2]string{},
|
|
|
|
)
|
|
|
|
|
2017-09-08 12:16:21 +00:00
|
|
|
ns.AddMethodMapping(ctx.Conditional,
|
|
|
|
[]string{"cond"},
|
|
|
|
[][2]string{
|
|
|
|
{`{{ cond (eq (add 2 2) 4) "2+2 is 4" "what?" | safeHTML }}`, `2+2 is 4`},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2017-05-01 16:40:34 +00:00
|
|
|
return ns
|
2017-04-30 17:33:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal.AddTemplateFuncsNamespace(f)
|
|
|
|
}
|