alps/plugins/base/template.go

63 lines
1.1 KiB
Go
Raw Normal View History

2020-05-13 12:07:44 +00:00
package alpsbase
2019-12-17 10:28:47 +00:00
import (
"html/template"
"net/url"
"strings"
2019-12-17 10:28:47 +00:00
"time"
2020-11-13 17:28:46 +00:00
"github.com/dustin/go-humanize"
2019-12-17 10:28:47 +00:00
"github.com/emersion/go-imap"
)
const (
inputDateLayout = "2006-01-02"
inputTimeLayout = "15:04"
)
2019-12-17 10:28:47 +00:00
var templateFuncs = template.FuncMap{
"tuple": func(values ...interface{}) []interface{} {
return values
},
2021-08-04 01:20:45 +00:00
"pathescape": url.PathEscape,
2019-12-17 10:28:47 +00:00
"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
}
},
2021-08-04 01:20:45 +00:00
"join": strings.Join,
"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)
},
2020-11-13 17:28:46 +00:00
"humantime": humanize.Time,
2019-12-17 10:28:47 +00:00
}