mirror of
https://github.com/btouchard/ackify-ce.git
synced 2026-02-09 07:18:36 -06:00
- Move templates from web/templates/ to webtemplates/templates/ - Replace file-based template loading with Go embed - Remove external template directory dependency from Dockerfile - Add webtemplates package with embedded template functionality - Include comprehensive tests for embedded templates - Update server initialization to use new embedded template system This change makes the application self-contained by embedding templates directly in the binary, eliminating the need for external template files at runtime.
31 lines
857 B
Go
31 lines
857 B
Go
package webtemplates
|
|
|
|
import (
|
|
"embed"
|
|
"fmt"
|
|
"html/template"
|
|
)
|
|
|
|
//go:embed templates/*.tpl
|
|
var TemplatesFS embed.FS
|
|
|
|
// InitTemplates initializes the HTML templates from embedded files
|
|
func InitTemplates() (*template.Template, error) {
|
|
// Parse the base template first
|
|
tmpl, err := template.New("base").ParseFS(TemplatesFS, "templates/base.html.tpl")
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to parse base template: %w", err)
|
|
}
|
|
|
|
// Parse the additional templates
|
|
additionalTemplates := []string{"templates/index.html.tpl", "templates/sign.html.tpl", "templates/signatures.html.tpl", "templates/embed.html.tpl"}
|
|
for _, templateFile := range additionalTemplates {
|
|
_, err = tmpl.ParseFS(TemplatesFS, templateFile)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to parse template %s: %w", templateFile, err)
|
|
}
|
|
}
|
|
|
|
return tmpl, nil
|
|
}
|