From 052b51f0df91054d4300e75fe39759c5152423be Mon Sep 17 00:00:00 2001 From: surtur Date: Sun, 17 Jul 2022 13:28:45 +0200 Subject: [PATCH] go(report): rework gen.go,report.tmpl make report include `report_base.tex` file verbatim and save it in `out/tex/report.tex` as a base file of the report. currently, this is done when running `go generate ./report` but there are plans to switch from that to emitting the file during runtime, as is done with all other templates. --- report/gen.go | 59 ++++++++++++++-------------------------------- report/report.tmpl | 9 ++----- 2 files changed, 20 insertions(+), 48 deletions(-) diff --git a/report/gen.go b/report/gen.go index 0b8e55a..894674a 100644 --- a/report/gen.go +++ b/report/gen.go @@ -7,64 +7,41 @@ package main import ( + _ "embed" "log" "os" "text/template" "time" ) +var ( + //go:embed report_base.tex + reportBase []byte + + //go:embed report.tmpl + tmplReportFile []byte +) + func main() { - // colAlign sets the alignment of latex table columns. - colAlign := []string{ - "l", - "c", - "c", - "c", - "c", - "c", - } - results := []float64{ - 161.032187, - 125.03484, - 80321, - 85.0362432, - -4.466, - 66.0008, - } - colNames := []string{ - "func name", - "min", - "max", - "mean", - "median", - "stdDev", - } - - fName := "report.tex" - paths := []string{ - "report.tmpl", - } + fName := "../out/tex/report.tex" f, err := os.Create(fName) - if err != nil { log.Fatal(err) } defer f.Close() - reportTemplate := template.Must(template.ParseFiles(paths...)) + tmplReport := template.New("report") + tmplReport = template.Must(tmplReport.Parse(string(tmplReportFile))) - err = reportTemplate.Execute(f, struct { - Timestamp time.Time - ColNames []string - Results []float64 - ColAlign []string + err = tmplReport.Execute(f, struct { + ReportBase string + Timestamp time.Time }{ - Timestamp: time.Now(), - ColNames: colNames, - Results: results, - ColAlign: colAlign, + ReportBase: string(reportBase), + Timestamp: time.Now(), }) + if err != nil { log.Println(err) } diff --git a/report/report.tmpl b/report/report.tmpl index 1ed92fc..be7afd0 100644 --- a/report/report.tmpl +++ b/report/report.tmpl @@ -6,11 +6,6 @@ % This file is a part of the math-optim project. % project homepage: https://git.dotya.ml/wanderer/math-optim/ -\begin{tabular}{ ||{{- range $i, $v := .ColAlign }}{{$v}}| {{- end}}| } - {{ range $i, $v := .ColNames }}{{$v }} & {{ end}}\\ -{{- range .Results }} - {{ printf "%f &" . }} \\ -{{- end }} -\end{tabular} +{{- .ReportBase -}} -% vim: ft=gotexttmpl.tex ts=2 bs=2 +% vim: ft=gotexttmpl ts=2 bs=2 expandtab