feat: ent ORM, admin UI, client auth, Fyne GUI, Windows/MSI packaging
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"embed"
|
||||
"html/template"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//go:embed templates/*.html
|
||||
var templateFS embed.FS
|
||||
|
||||
var tmpl *template.Template
|
||||
|
||||
func init() {
|
||||
funcMap := template.FuncMap{
|
||||
"lower": strings.ToLower,
|
||||
}
|
||||
tmpl = template.Must(template.New("").Funcs(funcMap).ParseFS(templateFS, "templates/*.html"))
|
||||
}
|
||||
|
||||
func renderTemplate(w io.Writer, name string, data map[string]any) error {
|
||||
return tmpl.ExecuteTemplate(w, name, data)
|
||||
}
|
||||
|
||||
func renderToString(name string, data map[string]any) string {
|
||||
var buf bytes.Buffer
|
||||
if err := tmpl.ExecuteTemplate(&buf, name, data); err != nil {
|
||||
return "<p>Error rendering template</p>"
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func renderLayout(w io.Writer, title string, content template.HTML) error {
|
||||
return tmpl.ExecuteTemplate(w, "layout.html", map[string]any{
|
||||
"Title": title,
|
||||
"Content": content,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user