aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/template.go
blob: 7d6e12612a851e2efc1c71852b0522657775d783 (plain) (blame)
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
package alpsbase

import (
	"html/template"
	"net/url"
	"strings"
	"time"

	"github.com/dustin/go-humanize"
	"github.com/emersion/go-imap"
)

const (
	inputDateLayout = "2006-01-02"
	inputTimeLayout = "15:04"
)

var templateFuncs = template.FuncMap{
	"tuple": func(values ...interface{}) []interface{} {
		return values
	},
	"pathescape": func(s string) string {
		return url.PathEscape(s)
	},
	"formatdate": func(t time.Time) string {
		return t.Format("Mon Jan 02 15:04")
	},
	"formatflag": func(flag string) string {
		switch flag {
		case imap.SeenFlag:
			return "Seen"
		case imap.AnsweredFlag:
			return "Answered"
		case imap.FlaggedFlag:
			return "Starred"
		case imap.DraftFlag:
			return "Draft"
		default:
			return flag
		}
	},
	"ismutableflag": func(flag string) bool {
		switch flag {
		case imap.AnsweredFlag, imap.DeletedFlag, imap.DraftFlag:
			return false
		default:
			return true
		}
	},
	"join": func(l []string, sep string) string {
		return strings.Join(l, sep)
	},
	"formatinputdate": func(t time.Time) string {
		if t.IsZero() {
			return ""
		}
		return t.Format(inputDateLayout)
	},
	"formatinputtime": func(t time.Time) string {
		if t.IsZero() {
			return ""
		}
		return t.Format(inputTimeLayout)
	},
	"humantime": humanize.Time,
}