go(report): embed all templates
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-07-17 11:36:59 +02:00
parent 446f63b59e
commit 7742642e14
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
3 changed files with 20 additions and 34 deletions

@ -4,6 +4,7 @@
package report
import (
_ "embed"
"log"
"os"
"text/template"
@ -22,7 +23,11 @@ type allThePics struct {
TexFiles []picTexFiles
}
var allPics = &allThePics{}
var (
allPics = &allThePics{}
//go:embed allpics.tmpl
tmplAllPicsFile []byte
)
// SaveTexAllPics feeds all paths of generated pics to a template that creates
// `allpics.tex` file, which then aggregates all tex files tracking plot pics
@ -30,18 +35,9 @@ var allPics = &allThePics{}
func SaveTexAllPics() {
a := allPics
texAllPicsFile := GetTexDir() + "allpics" + ".tex"
tmplAllPicsFile := "report/allpics.tmpl"
if _, err := os.Stat(tmplAllPicsFile); err != nil {
// TODO(me): fix this.
// this block is relevant for the unit test path, somehow the file is
// not found as defined above.
log.Println(err, `, weird test behaviour , prepending "../"`)
tmplAllPicsFile = "../" + tmplAllPicsFile
}
tmplAllPics := template.Must(template.ParseFiles(tmplAllPicsFile))
tmplAllPics := template.New("allpics")
tmplAllPics = template.Must(tmplAllPics.Parse(string(tmplAllPicsFile)))
f, err := os.Create(texAllPicsFile)
if err != nil {

@ -4,6 +4,7 @@
package report
import (
_ "embed"
"log"
"os"
"sort"
@ -26,6 +27,9 @@ type PicList struct {
Pics []Pic
}
//go:embed pics.tmpl
var tmplPicsFile []byte
// NewPic returns a new copy of Pic.
func NewPic() *Pic {
return &Pic{}
@ -46,18 +50,9 @@ func SavePicsToFile(pls []PicList, algoName string) {
for _, p := range pls {
safeName := util.SanitiseFName(p.Algo + "-" + p.Bench)
texPicsFile := GetTexDir() + "pics-" + safeName + ".tex"
tmplPicsFile := "report/pics.tmpl"
tmplPics := template.New("pics")
if _, err := os.Stat(tmplPicsFile); err != nil {
// TODO(me): fix this, same as in table.go.
// this block is relevant for the unit test path, somehow the file is
// not found as defined above.
log.Println(err, `, weird test behaviour , prepending "../"`)
tmplPicsFile = "../" + tmplPicsFile
}
tmplPics := template.Must(template.ParseFiles(tmplPicsFile))
tmplPics = template.Must(tmplPics.Parse(string(tmplPicsFile)))
paths = append(paths, texPicsFile)
// keep the slice sorted.

@ -4,6 +4,7 @@
package report
import (
_ "embed"
"log"
"os"
"text/template"
@ -25,6 +26,9 @@ type Row struct {
Values []float64
}
//go:embed table.tmpl
var tmplTableFile []byte
func NewTable() *Table {
return &Table{}
}
@ -36,18 +40,9 @@ func NewRow() *Row {
func SaveTableToFile(t Table) {
safeName := util.SanitiseFName(t.Algo)
texTableFile := GetTexDir() + "table-" + safeName + ".tex"
tmplTableFile := "report/table.tmpl"
tmplTable := template.New("table")
if _, err := os.Stat(tmplTableFile); err != nil {
// TODO(me): fix this.
// this block is relevant for the unit test path, somehow the file is
// not found as defined above.
log.Println(err, `, weird test behaviour , prepending "../"`)
tmplTableFile = "../" + tmplTableFile
}
tmplTable := template.Must(template.ParseFiles(tmplTableFile))
tmplTable = template.Must(tmplTable.Parse(string(tmplTableFile)))
ttf := tableTexFiles{Algo: t.Algo, FilePaths: []string{texTableFile}}
allTables.TexFiles = append(allTables.TexFiles, ttf)