diff --git a/.log b/.log new file mode 100644 index 0000000..0c0de36 --- /dev/null +++ b/.log @@ -0,0 +1,27 @@ +This is pdfTeX, Version 3.141592653-2.6-1.40.25 (TeX Live 2023/Fedora 40) (preloaded format=pdflatex 2024.11.11) 11 NOV 2024 15:42 +entering extended mode + restricted \write18 enabled. + %&-line parsing enabled. +**/home/theo/projects/Anemon/assets/latex/output/.gitignore +(/home/theo/projects/Anemon/assets/latex/output/.gitignore +LaTeX2e <2022-11-01> patch level 1 +L3 programming layer <2023-02-22> +! You can't use `macro parameter character #' in vertical mode. +l.1 # + Ignore everything in this directory +? +! Emergency stop. +l.1 + +End of file on the terminal! + + +Here is how much of TeX's memory you used: + 17 strings out of 476041 + 526 string characters out of 5793163 + 1849388 words of memory out of 6000000 + 20570 multiletter control sequences out of 15000+600000 + 512287 words of font info for 32 fonts, out of 8000000 for 9000 + 1137 hyphenation exceptions out of 8191 + 13i,0n,12p,126b,10s stack positions out of 10000i,1000n,20000p,200000b,200000s +! ==> Fatal error occurred, no output PDF file produced! diff --git a/Makefile b/Makefile index 3dd0a92..c7728fa 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,9 @@ run: echo "Not yet complete" +clean: + rm ./assets/latex/output/* + build: go build @@ -12,4 +15,4 @@ tidy: go mod tidy test: - go test ./... + go test -v ./... diff --git a/internal/adapters/input/cli.go b/internal/adapters/input/cli.go index cad8d80..1c024d0 100644 --- a/internal/adapters/input/cli.go +++ b/internal/adapters/input/cli.go @@ -11,6 +11,7 @@ func GenerateCVFromMarkDownToLatex(root string)error{ var paramsSource core.SourceParams = &YamlSource{} var templateReader core.TemplateReader = &output.LatexReader{} var templateProccesor core.TemplateProcessor = &output.LatexProccesor{} + var compiler core.Compiler = &output.LatexCompiler{} service := &core.CVService{} - return service.GenerateTemplates(root,source, paramsSource,templateReader,templateProccesor) + return service.GenerateTemplates(root,source, paramsSource,templateReader,templateProccesor,compiler) } diff --git a/internal/adapters/output/compiler.go b/internal/adapters/output/compiler.go new file mode 100644 index 0000000..738e479 --- /dev/null +++ b/internal/adapters/output/compiler.go @@ -0,0 +1,45 @@ +package output + +import ( + "fmt" + "log/slog" + "os" + "os/exec" + "strings" +) + + +const COMPILER = "pdflatex" +type LatexCompiler struct{} + +//Compile the template into PDF +func (*LatexCompiler) CompileTemplate(root string)error{ + templates,err := getListOfTemplate(root);if err != nil { + return err + } + for _,template := range templates{ + cmd := exec.Command(COMPILER,"-interaction=nonstopmode", + "-output-directory="+root+"/assets/latex/output", template ) + log, err := cmd.Output(); if err != nil { + slog.Info("---FROM pdflatex ---\n"+string(log)) + slog.Error("failed to compile file:"+template) + } + } + return nil +} + +//Return the path of latex file inside the template directory +func getListOfTemplate(root string)([]string, error){ + var res []string + templates, err := os.ReadDir(root + "/assets/latex/output"); if err != nil { + slog.Error("failed to read directory because: "+ err.Error()) + return res,err + } + for _, template := range templates { + if strings.HasSuffix(template.Name(),".tex"){ + res = append(res, root+"/assets/latex/output/"+template.Name()) + } + } + fmt.Println(res) + return res,nil +} diff --git a/internal/adapters/output/latex_test.go b/internal/adapters/output/latex_test.go index 245917d..e6575c2 100644 --- a/internal/adapters/output/latex_test.go +++ b/internal/adapters/output/latex_test.go @@ -2,6 +2,8 @@ package output import ( "anemon/internal/core" + "path/filepath" + "os" "strings" "testing" ) @@ -290,3 +292,37 @@ func TestApplyInfoToTemplate(t *testing.T) { } } + +func TestGetListOfTemplate(t *testing.T) { + root := "testdata" + templateDir := filepath.Join(root, "assets", "latex", "output") + err := os.MkdirAll(templateDir, os.ModePerm) + if err != nil { + t.Fatalf("setup failed: %v", err) + } + defer os.RemoveAll(root) + + files := []string{"foo.tex", "bar.tex","garbage"} + for _, file := range files { + f, err := os.Create(filepath.Join(templateDir, file)) + if err != nil { + t.Fatalf("failed to create test file: %v", err) + } + f.Close() + } + + got, err := getListOfTemplate(root) + if err != nil { + t.Fatalf("getListOfTemplate returned an error: %v", err) + } + expected := files + if len(got) != len(expected)-1{//Should ommit garbage + t.Errorf("expected %d files, got %d", len(expected), len(got)) + } + for _, filePath := range got { + _, err := os.Stat(filePath) + if err != nil { + t.Errorf("expected path %s not found: %v", filePath, err) + } + } +} diff --git a/internal/core/generate.go b/internal/core/generate.go index bc95d69..5084912 100644 --- a/internal/core/generate.go +++ b/internal/core/generate.go @@ -8,10 +8,9 @@ import ( type CVService struct{} -//TODO apply information in header of CV //generate the template for the cvs defined in the assets directory func (g *CVService) GenerateTemplates(root string, source Source, paramsSource SourceParams, - templateReader TemplateReader, templateProcessor TemplateProcessor)error{ + templateReader TemplateReader, templateProcessor TemplateProcessor, compiler Compiler)error{ slog.Info("--Generating CVs--") cvs,err := source.GetCVsFrom(root);if err != nil{ return err } params,err := paramsSource.GetParamsFrom(root);if err != nil{ return err } @@ -40,10 +39,13 @@ func (g *CVService) GenerateTemplates(root string, source Source, paramsSource S } } } + compiler.CompileTemplate(root) return nil } //Sorte a slice of items by the number of keyword +// +//The sort is done in ascending order as the section append work like a stack(Lifo) func sortByScore(items []string, keywords []string){ sort.Slice(items, func(i, j int) bool { return getScore(items[i],keywords)