aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/base/template.go21
-rw-r--r--plugins/caldav/plugin.go17
-rw-r--r--plugins/carddav/plugin.go7
3 files changed, 21 insertions, 24 deletions
diff --git a/plugins/base/template.go b/plugins/base/template.go
index 482674a..7d85db6 100644
--- a/plugins/base/template.go
+++ b/plugins/base/template.go
@@ -3,11 +3,17 @@ package alpsbase
import (
"html/template"
"net/url"
+ "strings"
"time"
"github.com/emersion/go-imap"
)
+const (
+ inputDateLayout = "2006-01-02"
+ inputTimeLayout = "15:04"
+)
+
var templateFuncs = template.FuncMap{
"tuple": func(values ...interface{}) []interface{} {
return values
@@ -40,4 +46,19 @@ var templateFuncs = template.FuncMap{
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)
+ },
}
diff --git a/plugins/caldav/plugin.go b/plugins/caldav/plugin.go
index e8d14a9..03f8214 100644
--- a/plugins/caldav/plugin.go
+++ b/plugins/caldav/plugin.go
@@ -2,10 +2,8 @@ package alpscaldav
import (
"fmt"
- "html/template"
"net/http"
"net/url"
- "time"
"git.sr.ht/~emersion/alps"
)
@@ -64,21 +62,6 @@ func newPlugin(srv *alps.Server) (alps.Plugin, error) {
registerRoutes(&p, u)
- p.TemplateFuncs(template.FuncMap{
- "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)
- },
- })
-
return p.Plugin(), nil
}
diff --git a/plugins/carddav/plugin.go b/plugins/carddav/plugin.go
index 225c98f..ae1ab14 100644
--- a/plugins/carddav/plugin.go
+++ b/plugins/carddav/plugin.go
@@ -4,7 +4,6 @@ import (
"fmt"
"net/http"
"net/url"
- "strings"
"git.sr.ht/~emersion/alps"
alpsbase "git.sr.ht/~emersion/alps/plugins/base"
@@ -112,12 +111,6 @@ func newPlugin(srv *alps.Server) (alps.Plugin, error) {
registerRoutes(p)
- p.TemplateFuncs(map[string]interface{}{
- "join": func(l []string, sep string) string {
- return strings.Join(l, sep)
- },
- })
-
p.Inject("compose.html", func(ctx *alps.Context, _data alps.RenderData) error {
data := _data.(*alpsbase.ComposeRenderData)