package chrome import ( "embed" "html/template" ) //go:embed templates/chrome.tmpl var templateFS embed.FS // Attach parses the shared chrome partials ("srht-nav", "srht-sections", // "srht-env-banner", "srht-head-links", "srht-repo-list", "srht-repo-table") // into t, so a service layout can invoke them. Call it once per template set, // before the layout that references the partials is executed. // // It installs Funcs first, because the partials call them: an unknown function // is a parse error, so a caller who had not merged Funcs would get a startup // panic naming a template it never wrote. Installing them here also means the // partials keep working when a service overrides a helper afterwards — its own // Funcs call wins for its own templates. func Attach(t *template.Template) (*template.Template, error) { return t.Funcs(Funcs()).ParseFS(templateFS, "templates/chrome.tmpl") } // MustAttach is Attach for the common wire-up-at-startup path, where a parse // failure is a programmer error. func MustAttach(t *template.Template) *template.Template { t, err := Attach(t) if err != nil { panic(err) } return t }