-
Notifications
You must be signed in to change notification settings - Fork 3
/
func.go
37 lines (31 loc) · 894 Bytes
/
func.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
package template
import (
"fmt"
"github.com/kataras/iris/v12/view"
"html/template"
"regexp"
"strings"
)
func Init(engine *view.HTMLEngine) {
engine.AddFunc("indent", Indent)
engine.AddFunc("nindent", NIndent)
engine.AddFunc("mod", Mod)
engine.AddFunc("nmod", NMod)
}
func Indent(n int, html template.HTML) template.HTML {
startOfLine := regexp.MustCompile(`(?m)^`)
indentation := strings.Repeat(" ", n)
return template.HTML(startOfLine.ReplaceAllLiteralString(string(html), indentation))
}
func NIndent(n int, html template.HTML) template.HTML {
startOfLine := regexp.MustCompile(`(?m)^`)
indentation := strings.Repeat(" ", n)
text := startOfLine.ReplaceAllLiteralString(string(html), indentation)
return template.HTML(fmt.Sprintf("\n%s", text))
}
func Mod(num int, m int) bool {
return (num+1)%m == 0
}
func NMod(num int, m int, eq int) bool {
return (num+1)%m == eq
}