-
Notifications
You must be signed in to change notification settings - Fork 2
/
templateFunctions.go
76 lines (62 loc) · 1.64 KB
/
templateFunctions.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
68
69
70
71
72
73
74
75
76
package heyfyiserver
import (
"html/template"
"strconv"
"strings"
)
var funcMap = template.FuncMap{
"GetViewFactUrl": GetViewFactUrl,
"GetSignUpUrl": GetSignUpUrl,
"GetSignInUrl": GetSignInUrl,
"GetSignOutUrl": GetSignOutUrl,
"GetCreateFactUrl": GetCreateFactUrl,
"GetHomeUrl": GetHomeUrl,
"GetListFactUrl": GetListFactUrl,
"GetRequestPasswordResetUrl": GetRequestPasswordResetUrl,
"GetDeleteFactUrl": GetDeleteFactUrl,
"TruncateString": TruncateString,
} //this provides templates with the ability to run useful functions
func GetViewFactUrl(factId int64) string {
if factId == 0 {
return "#error"
}
return ViewFactUrl.Make("factId", strconv.FormatInt(factId, 10))
}
func GetSignUpUrl() string {
return SignUpUrl.Make()
}
func GetSignInUrl() string {
return SignInUrl.Make()
}
func GetSignOutUrl() string {
return SignOutUrl.Make()
}
func GetCreateFactUrl() string {
return CreateFactUrl.Make()
}
func GetHomeUrl() string {
return HomeUrl.Make()
}
func GetListFactUrl() string {
return ListFactUrl.Make()
}
func GetRequestPasswordResetUrl() string {
return RequestPasswordResetUrl.Make()
}
func GetDeleteFactUrl(factId int64) string {
return DeleteFactUrl.Make("factId", strconv.FormatInt(factId, 10))
}
//Smart truncation function
func TruncateString(s string, charLimit int) string {
if len(s) < charLimit {
return s
}
//Return up to the last complete word + "..."
s2 := s[:charLimit-3]
s2ind := strings.LastIndex(s2, " ")
if s2ind >= 0 {
return s2[:s2ind] + "..."
}
//couldn't find a word boundary
return s2 + "..."
}