Workaround template functions not loaded
This is a hacky workaround to make things work until we find a better solution. Closes: https://todo.sr.ht/~emersion/alps/96
This commit is contained in:
parent
522454e009
commit
1f9fe0b169
|
@ -3,11 +3,17 @@ package alpsbase
|
||||||
import (
|
import (
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/emersion/go-imap"
|
"github.com/emersion/go-imap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
inputDateLayout = "2006-01-02"
|
||||||
|
inputTimeLayout = "15:04"
|
||||||
|
)
|
||||||
|
|
||||||
var templateFuncs = template.FuncMap{
|
var templateFuncs = template.FuncMap{
|
||||||
"tuple": func(values ...interface{}) []interface{} {
|
"tuple": func(values ...interface{}) []interface{} {
|
||||||
return values
|
return values
|
||||||
|
@ -40,4 +46,19 @@ var templateFuncs = template.FuncMap{
|
||||||
return true
|
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)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,8 @@ package alpscaldav
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.sr.ht/~emersion/alps"
|
"git.sr.ht/~emersion/alps"
|
||||||
)
|
)
|
||||||
|
@ -64,21 +62,6 @@ func newPlugin(srv *alps.Server) (alps.Plugin, error) {
|
||||||
|
|
||||||
registerRoutes(&p, u)
|
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
|
return p.Plugin(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"git.sr.ht/~emersion/alps"
|
"git.sr.ht/~emersion/alps"
|
||||||
alpsbase "git.sr.ht/~emersion/alps/plugins/base"
|
alpsbase "git.sr.ht/~emersion/alps/plugins/base"
|
||||||
|
@ -112,12 +111,6 @@ func newPlugin(srv *alps.Server) (alps.Plugin, error) {
|
||||||
|
|
||||||
registerRoutes(p)
|
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 {
|
p.Inject("compose.html", func(ctx *alps.Context, _data alps.RenderData) error {
|
||||||
data := _data.(*alpsbase.ComposeRenderData)
|
data := _data.(*alpsbase.ComposeRenderData)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue