diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2022-01-24 22:23:25 +0100 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2022-01-24 22:23:25 +0100 |
commit | fe48f136de25afcaba20ebceb586b1b12a58bdf8 (patch) | |
tree | 4d9d217f0dbe830e4d24ddb4e345b520fd08bc18 /template.go | |
parent | ab525a79df93487bea24cdbc6caabac8a3bdded2 (diff) | |
download | engarde-importer-fe48f136de25afcaba20ebceb586b1b12a58bdf8.tar.gz engarde-importer-fe48f136de25afcaba20ebceb586b1b12a58bdf8.tar.bz2 engarde-importer-fe48f136de25afcaba20ebceb586b1b12a58bdf8.zip |
Write competition.egw
Diffstat (limited to 'template.go')
-rw-r--r-- | template.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/template.go b/template.go index aa16727..036f806 100644 --- a/template.go +++ b/template.go @@ -7,15 +7,20 @@ import ( "io/fs" "os" "path" + "text/template" ) const verbatimPath = "templates/verbatim" const participantsName = "tireur.txt" const clubsName = "club.txt" +const competitionName = "competition.egw" //go:embed templates/verbatim var verbatim embed.FS +//go:embed templates/competition.egw.tpl +var competition string + func writeVerbatimFile(outputDir string, entry fs.DirEntry) error { inName := path.Join(verbatimPath, entry.Name()) @@ -71,6 +76,10 @@ func write(config EngardeConfig, participants []participant, clubs []club) error return fmt.Errorf("writing club data: %w", err) } + if err := writeCompetition(config.outputDir, config); err != nil { + return fmt.Errorf("writing competition file: %w", err) + } + return nil } @@ -114,3 +123,24 @@ func writeEngarde(outputDir, fileName string, entries []engarde) error { return nil } + +func writeCompetition(outputDir string, config EngardeConfig) error { + tpl, err := template.New(competitionName).Parse(competition) + if err != nil { + return fmt.Errorf("parsing template '%s': %w", competitionName, err) + } + + outName := path.Join(outputDir, competitionName) + output, err := os.Create(outName) + if err != nil { + return fmt.Errorf("creating '%s': %w", outName, err) + } + defer output.Close() + + encodedOutput := encodedWriter(output) + + if err = tpl.Execute(encodedOutput, config); err != nil { + return fmt.Errorf("executing template '%s': %w", competitionName, err) + } + return nil +} |