2024-12-23 20:57:58 -05:00
|
|
|
package ui
|
|
|
|
|
2024-12-30 15:00:42 -05:00
|
|
|
import (
|
|
|
|
"embed"
|
|
|
|
"io"
|
|
|
|
"text/template"
|
|
|
|
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
)
|
2024-12-23 20:57:58 -05:00
|
|
|
|
|
|
|
//go:embed *.html
|
|
|
|
var htmlFS embed.FS
|
|
|
|
|
|
|
|
func HTMLFS() embed.FS {
|
|
|
|
return htmlFS
|
|
|
|
}
|
2024-12-30 15:00:42 -05:00
|
|
|
|
|
|
|
type Renderer struct {
|
|
|
|
templates *template.Template
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *Renderer) Render(w io.Writer, name string, data any, c echo.Context) error {
|
|
|
|
return t.templates.ExecuteTemplate(w, name, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewRenderer() *Renderer {
|
|
|
|
return &Renderer{
|
|
|
|
templates: template.Must(template.ParseFS(HTMLFS(), "*html")),
|
|
|
|
}
|
|
|
|
}
|