aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/html
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2022-02-17 13:41:47 +0000
committerAleksandr Nogikh <wp32pw@gmail.com>2022-02-25 18:57:42 +0100
commit78eae57185479f6e959ca2b5822a66297857d5c6 (patch)
tree1be826f98379076cbd863475283764fc71218662 /pkg/html
parent22a416f7f2e32f9fc2ffc9055e67b804a39aaf36 (diff)
tools/syz-testbed: store html templates in files
Diffstat (limited to 'pkg/html')
-rw-r--r--pkg/html/html.go14
1 files changed, 12 insertions, 2 deletions
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 = `<style type="text/css" media="screen">%v</style><script>%v</script>`
- 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 = `<style type="text/css" media="screen">%v</style><script>%v</script>`
+ return fmt.Sprintf(headTempl, style, js)
+}
+
var Funcs = template.FuncMap{
"link": link,
"optlink": optlink,