From 78eae57185479f6e959ca2b5822a66297857d5c6 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Thu, 17 Feb 2022 13:41:47 +0000 Subject: tools/syz-testbed: store html templates in files --- pkg/html/html.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'pkg/html') diff --git a/pkg/html/html.go b/pkg/html/html.go index 0b6fdaa75..991f7b37a 100644 --- a/pkg/html/html.go +++ b/pkg/html/html.go @@ -8,6 +8,7 @@ package html import ( "fmt" "html/template" + "io/fs" "reflect" "strings" texttemplate "text/template" @@ -17,8 +18,7 @@ import ( ) func CreatePage(page string) *template.Template { - const headTempl = `` - page = strings.Replace(page, "{{HEAD}}", fmt.Sprintf(headTempl, style, js), 1) + page = strings.Replace(page, "{{HEAD}}", getHeadTemplate(), 1) return template.Must(template.New("").Funcs(Funcs).Parse(page)) } @@ -26,10 +26,20 @@ func CreateGlob(glob string) *template.Template { return template.Must(template.New("").Funcs(Funcs).ParseGlob(glob)) } +func CreateFromFS(fs fs.FS, patterns ...string) *template.Template { + t := template.Must(template.New("syz-head").Funcs(Funcs).Parse(getHeadTemplate())) + return template.Must(t.New("").Funcs(Funcs).ParseFS(fs, patterns...)) +} + func CreateTextGlob(glob string) *texttemplate.Template { return texttemplate.Must(texttemplate.New("").Funcs(texttemplate.FuncMap(Funcs)).ParseGlob(glob)) } +func getHeadTemplate() string { + const headTempl = `` + return fmt.Sprintf(headTempl, style, js) +} + var Funcs = template.FuncMap{ "link": link, "optlink": optlink, -- cgit mrf-deployment