-
Notifications
You must be signed in to change notification settings - Fork 4
/
template.go
52 lines (44 loc) · 1.07 KB
/
template.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
package svg
import (
"fmt"
"strings"
"github.com/samber/lo"
"projectforge.dev/projectforge/app/util"
)
func template(svgs []*SVG, linebreak string) string {
out := strings.Builder{}
w := func(s string) {
out.WriteString(s)
out.WriteString(linebreak)
}
maxKeyLength := 0
var keys []string
lo.ForEach(svgs, func(svg *SVG, _ int) {
if len(svg.Key) > maxKeyLength {
maxKeyLength = len(svg.Key)
}
switch svg.Key {
case "search":
// noop
default:
keys = append(keys, fmt.Sprintf(`%q`, svg.Key))
}
})
w("// Code generated from files in [client/src/svg]. See " + util.AppURL + " for details. DO NOT EDIT.")
w("package util")
w("")
w("var SVGLibrary = map[string]string{")
msg := "\t%-" + fmt.Sprintf("%d", maxKeyLength+3) + "s `%s`,"
lo.ForEach(svgs, func(fn *SVG, _ int) {
w(fmt.Sprintf(msg, `"`+fn.Key+`":`, fn.Markup))
})
w("}")
w("")
w("//nolint:lll")
w("var SVGIconKeys = []string{" + strings.Join(keys, ", ") + "}")
w("")
w("func RandomIcon() string {")
w("\treturn SVGIconKeys[RandomInt(len(SVGIconKeys))]")
w("}")
return out.String()
}