package pdf import ( "embed" "fmt" "log/slog" "os" "path/filepath" "text/template" "time" "codeflow.dananglin.me.uk/apollo/spruce/internal/cv" tf "codeflow.dananglin.me.uk/apollo/spruce/internal/templatefuncs" ) //go:embed templates/tex/* var templates embed.FS // tex generates the CV document as a Tex file. func tex(input, tempDir string, historyLimit time.Time) (string, error) { slog.Info("Creating the Tex file.") data, err := cv.NewCVFromFile(input) if err != nil { return "", fmt.Errorf("unable to create a new CV value from %s; %w", input, err) } output := filepath.Join(tempDir, "cv.tex") file, err := os.Create(output) if err != nil { return "", fmt.Errorf("unable to create output file %s; %w", output, err) } defer file.Close() fmap := template.FuncMap{ "notLastElement": tf.NotLastElement, "join": tf.JoinSentences, "durationToString": tf.FormatDuration, "withinTimePeriod": tf.WithinTimePeriod(historyLimit), "location": tf.Location, } tmpl := template.Must(template.New("cv.tmpl.tex"). Funcs(fmap). Delims("<<", ">>"). ParseFS(templates, "templates/tex/*.tmpl.tex"), ) if err = tmpl.Execute(file, data); err != nil { return "", fmt.Errorf("unable to execute the CV template. %w", err) } slog.Info("Tex file successfully created.", "filename", output) return output, nil }