-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtempalte_funcmap.go
67 lines (59 loc) · 2.12 KB
/
tempalte_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package protokit
import (
"html/template"
"sort"
"strings"
"github.com/sandwich-go/boost/xstrings"
)
func unescaped(str string) template.HTML { return template.HTML(str) }
func Slash2Underline(s string) string { return strings.ReplaceAll(s, "/", "_") }
func Slash2Dot(s string) string { return strings.ReplaceAll(s, "/", ".") }
func Underline2Dot(s string) string { return strings.ReplaceAll(s, "_", ".") }
func Dot2Underline(s string) string { return strings.ReplaceAll(s, ".", "_") }
func Dot2Slash(s string) string { return strings.ReplaceAll(s, ".", "/") }
func ReplaceEmpty(s string, old string) string { return strings.ReplaceAll(s, old, "") }
func SortedKeys(m map[string]string) []string {
var keys []string
for k := range m {
keys = append(keys, k)
}
sort.Strings(keys)
return keys
}
func SortedVals(m map[string]string) []string {
var vals []string
for _, v := range m {
vals = append(vals, v)
}
sort.Strings(vals)
return vals
}
func SortStrings(m []string) []string {
sort.Strings(m)
return m
}
func ReplaceEmptyAndTile(s string, old string) string {
return strings.Title(strings.ReplaceAll(s, old, ""))
}
func StringTitle(s string) string { return strings.Title(s) }
func ReplaceString(s string, old string, new string) string { return strings.ReplaceAll(s, old, new) }
func Join(elems []string, sep string) string { return strings.Join(elems, sep) }
var funcMap = template.FuncMap{
"unescaped": unescaped,
"slash2Underline": Slash2Underline,
"slash2Dot": Slash2Dot,
"underline2Dot": Underline2Dot,
"dot2Underline": Dot2Underline,
"dot2Slash": Dot2Slash,
"ReplaceEmpty": ReplaceEmpty,
"ReplaceEmptyAndTile": ReplaceEmptyAndTile,
"ReplaceString": ReplaceString,
"CamelCase": xstrings.CamelCase,
"SnakeCase": xstrings.SnakeCase,
"FirstLower": xstrings.FirstLower,
"FirstUpper": xstrings.FirstUpper,
"SortedKeys": SortedKeys,
"SortedVals": SortedVals,
"Join": Join,
"SortStrings": SortStrings,
}