-
Notifications
You must be signed in to change notification settings - Fork 0
/
funcmap.go
53 lines (43 loc) · 1.02 KB
/
funcmap.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
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright © 2020 Alexandre Kovac <contact@kovacou.com>.
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.
package templates
// Copyright © 2020 Alexandre Kovac <contact@kovacou.com>.
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.
import (
"encoding/json"
"html/template"
"strings"
"github.com/Masterminds/sprig"
"github.com/kovacou/go-convert"
"github.com/kovacou/go-types"
)
var (
FuncMap = types.Map{
// Treat as HTML
"html": func(v string) template.HTML {
return template.HTML(v)
},
// Treat as JS
"js": func(v interface{}) template.JS {
encoded, _ := json.Marshal(v)
return template.JS(encoded)
},
// Numeric manipulation
"sub": func(y, x int) int {
return x - y
},
// Strings
"ToLower": strings.ToLower,
"ToUpper": strings.ToUpper,
// Casts & Conversions
"Int": convert.Int,
"String": convert.String,
}
)
func init() {
FuncMap.Merge(sprig.FuncMap())
}