coverage~bigbes/sr-ht-ecore89fa694cchrome/templates.go

Coverage
80.0% 4/5 statements
Δ
+0.0
Blob
e37e280
Uncovered L30
1 package chrome
2
3 import (
4 "embed"
5 "html/template"
6 )
7
8 //go:embed templates/chrome.tmpl
9 var templateFS embed.FS
10
11 // Attach parses the shared chrome partials ("srht-nav", "srht-sections",
12 // "srht-env-banner", "srht-head-links", "srht-repo-list", "srht-repo-table")
13 // into t, so a service layout can invoke them. Call it once per template set,
14 // before the layout that references the partials is executed.
15 //
16 // It installs Funcs first, because the partials call them: an unknown function
17 // is a parse error, so a caller who had not merged Funcs would get a startup
18 // panic naming a template it never wrote. Installing them here also means the
19 // partials keep working when a service overrides a helper afterwards — its own
20 // Funcs call wins for its own templates.
21 15 func Attach(t *template.Template) (*template.Template, error) {
22 15 return t.Funcs(Funcs()).ParseFS(templateFS, "templates/chrome.tmpl")
23 15 }
24
25 // MustAttach is Attach for the common wire-up-at-startup path, where a parse
26 // failure is a programmer error.
27 15 func MustAttach(t *template.Template) *template.Template {
28 15 t, err := Attach(t)
29 15 if err != nil {
30 0 panic(err)
31 }
32 15 return t
33 }