2023-09-15 17:10:57 -04:00
|
|
|
/*
|
|
|
|
Package webcontent provides the content to be embedded in the binary executable
|
|
|
|
for the web app
|
|
|
|
*/
|
|
|
|
package webcontent
|
2023-09-17 01:12:46 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"embed"
|
|
|
|
"io"
|
|
|
|
"text/template"
|
|
|
|
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
)
|
|
|
|
|
2023-09-17 16:32:40 -04:00
|
|
|
//go:embed html/*.html
|
2023-09-17 01:12:46 -04:00
|
|
|
var htmlFS embed.FS
|
|
|
|
|
2023-09-17 16:32:40 -04:00
|
|
|
//go:embed js/*.js
|
|
|
|
var publicFS embed.FS
|
|
|
|
|
2023-09-17 01:12:46 -04:00
|
|
|
func HTMLFS() embed.FS {
|
|
|
|
return htmlFS
|
|
|
|
}
|
|
|
|
|
2023-09-17 16:32:40 -04:00
|
|
|
func PublicFS() embed.FS {
|
|
|
|
return publicFS
|
|
|
|
}
|
|
|
|
|
2023-09-17 01:12:46 -04:00
|
|
|
type Template struct {
|
|
|
|
templates *template.Template
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
|
|
|
|
return t.templates.ExecuteTemplate(w, name, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TemplateHTMLFS() *Template {
|
|
|
|
return &Template{
|
|
|
|
templates: template.Must(template.ParseFS(HTMLFS(), "html/*.html")),
|
|
|
|
}
|
|
|
|
}
|