2019-12-02 14:31:00 +00:00
|
|
|
package koushin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"html/template"
|
|
|
|
"io"
|
2019-12-03 16:31:53 +00:00
|
|
|
"net/url"
|
2019-12-02 14:31:00 +00:00
|
|
|
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
)
|
|
|
|
|
|
|
|
type tmpl struct {
|
|
|
|
t *template.Template
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *tmpl) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
|
|
|
|
return t.t.ExecuteTemplate(w, name, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func loadTemplates() (*tmpl, error) {
|
2019-12-03 12:07:25 +00:00
|
|
|
t, err := template.New("drmdb").Funcs(template.FuncMap{
|
|
|
|
"tuple": func(values ...interface{}) []interface{} {
|
|
|
|
return values
|
|
|
|
},
|
2019-12-03 16:31:53 +00:00
|
|
|
"pathescape": func(s string) string {
|
|
|
|
return url.PathEscape(s)
|
|
|
|
},
|
2019-12-03 12:07:25 +00:00
|
|
|
}).ParseGlob("public/*.html")
|
2019-12-02 14:31:00 +00:00
|
|
|
return &tmpl{t}, err
|
|
|
|
}
|