generated from clevergo/pkg-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsprig.go
41 lines (34 loc) · 883 Bytes
/
sprig.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
// Copyright 2020 CleverGo. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package jetsprig
import "github.com/CloudyKit/jet/v5"
// FuncMap is a set of functions.
type FuncMap map[string]jet.Func
// AttachTo attaches function to Set.
func (fm FuncMap) AttachTo(set *jet.Set) {
for name, fn := range fm {
set.AddGlobalFunc(name, fn)
}
}
var genericFuncMap = map[string]jet.Func{
// string
"join": Join,
"title": Title,
"trim": Trim,
"trimPrefix": TrimPrefix,
"trimSuffix": TrimSuffix,
// date
"now": Now,
"date": Date,
"dateInZone": DateInZone,
"ago": Ago,
}
// GenericFuncMap returns generic functions.
func GenericFuncMap() FuncMap {
m := make(FuncMap, len(genericFuncMap))
for name, fn := range genericFuncMap {
m[name] = fn
}
return m
}