/
template.go
73 lines (69 loc) · 1.52 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package app
import (
"html/template"
"time"
"github.com/dustin/go-humanize"
"github.com/acoshift/acourse/internal/pkg/config"
"github.com/acoshift/acourse/internal/pkg/course"
"github.com/acoshift/acourse/internal/pkg/markdown"
"github.com/acoshift/acourse/internal/pkg/payment"
)
func templateFunc() template.FuncMap {
return template.FuncMap{
"currency": func(v float64) string {
return humanize.FormatFloat("#,###.##", v)
},
"courseType": func(v int) string {
switch v {
case course.Live:
return "Live"
case course.Video:
return "Video"
case course.EBook:
return "eBook"
default:
return ""
}
},
"date": func(v time.Time) string {
return v.In(config.Location()).Format("02/01/2006")
},
"dateTime": func(v time.Time) string {
return v.In(config.Location()).Format("02/01/2006 15:04:05")
},
"dateInput": func(v time.Time) string {
return v.Format("2006-01-02")
},
"markdown": markdown.HTML,
"live": func() int {
return course.Live
},
"video": func() int {
return course.Video
},
"eBook": func() int {
return course.EBook
},
"pending": func() int {
return payment.Pending
},
"accepted": func() int {
return payment.Accepted
},
"rejected": func() int {
return payment.Rejected
},
"refunded": func() int {
return payment.Refunded
},
"html": func(v string) template.HTML {
return template.HTML(v)
},
"incr": func(v int) int {
return v + 1
},
"fallbackImage": func() string {
return "/-/placeholder-img.svg"
},
}
}