go(report_base): add in-text timestamp
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2022-07-18 03:27:08 +02:00
parent ed2aece330
commit 988c20885e
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D
3 changed files with 43 additions and 13 deletions

View File

@ -20,8 +20,8 @@
)
var (
//go:embed report_base.tex
reportBase []byte
//go:embed report_base.tmpl
tmplReportBaseFile []byte
//go:embed meta.sty
metaSty []byte
//go:embed report.tmpl
@ -38,6 +38,32 @@ func GetPicsDir() string {
return outPrefix + picsDir
}
func emitReportBaseTex() error {
fname := GetTexDir() + "report_base.tex"
f, err := os.Create(fname)
if err != nil {
log.Fatal(err)
}
defer f.Close()
tmplReportBase := template.New("report_base")
tmplReportBase = template.Must(tmplReportBase.Parse(string(tmplReportBaseFile)))
err = tmplReportBase.Execute(f, struct {
Timestamp time.Time
}{
Timestamp: time.Now(),
})
if err != nil {
log.Println(err)
}
return nil
}
func emitReportTex(fname string) error {
f, err := os.Create(fname)
if err != nil {
@ -50,11 +76,9 @@ func emitReportTex(fname string) error {
tmplReport = template.Must(tmplReport.Parse(string(tmplReportFile)))
err = tmplReport.Execute(f, struct {
ReportBase string
Timestamp time.Time
Timestamp time.Time
}{
ReportBase: string(reportBase),
Timestamp: time.Now(),
Timestamp: time.Now(),
})
if err != nil {
@ -81,9 +105,14 @@ func saveMetaSty() error {
// SaveAndPrint emits the tex files necessary to compile the report in full
// (report.tex, meta.sty) and prints the report.tex file to console.
func SaveAndPrint(doPrint bool) {
fname := "report.tex"
err := emitReportBaseTex()
if err != nil {
log.Fatal(err)
}
err := emitReportTex(fname)
reportFname := "report.tex"
err = emitReportTex(reportFname)
if err != nil {
log.Fatal(err)
}
@ -96,7 +125,7 @@ func SaveAndPrint(doPrint bool) {
if doPrint {
fmt.Fprint(os.Stderr, "\n* printing the report...\n\n")
fh, err := os.Open(fname)
fh, err := os.Open(reportFname)
if err != nil {
log.Fatal(err)
}

View File

@ -1,4 +1,4 @@
% Code generated by go generate; DO NOT EDIT.
% Code generated by math-optim; DO NOT EDIT.
% This file was generated by robots at
% {{ .Timestamp }}
% source: git.dotya.ml/wanderer/math-optim/report/report.tmpl
@ -8,7 +8,7 @@
% begin report.tmpl
{{ .ReportBase -}}
\input{out/tex/report_base.tex}
% end report.tmpl

View File

@ -36,8 +36,9 @@
\vspace*{\fill}
\begin{center}
\Large
This file was generated by robots.\\source:
\href{https://git.dotya.ml/wanderer/math-optim/}{\texttt{math-optim} project page}
The template of this file was generated by robots at\\
\texttt{ {{- .Timestamp -}} }\\
source: \href{https://git.dotya.ml/wanderer/math-optim/}{\texttt{math-optim} project page}
\end{center}
\vspace*{\fill}