From cb01d278b3731da32b628b28799ce70b91ea9b12 Mon Sep 17 00:00:00 2001 From: "Jip J. Dekker" Date: Wed, 13 Apr 2016 20:17:14 +0200 Subject: [PATCH] Adds a function to find all categories --- compiler/book.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/compiler/book.go b/compiler/book.go index c3bf1f4..bc1672b 100644 --- a/compiler/book.go +++ b/compiler/book.go @@ -18,6 +18,7 @@ import ( "os" "os/exec" "path/filepath" + "fmt" log "github.com/Sirupsen/logrus" "github.com/alecthomas/template" @@ -58,6 +59,7 @@ var bookTempl = ` func MakeBook(path string, opts *settings.Settings) { // Everything needs to be compiled CompileDir(path, opts) + fmt.Println(scoreCategories(&scores)) // Compile the book template var templ = template.Must(template.New("songBook").Parse(bookTempl)) @@ -97,3 +99,19 @@ func MakeBook(path string, opts *settings.Settings) { err = os.Remove(texPath) helpers.Check(err, "could not remove songbook latex template") } + +// scoreCategories returns a slice of all categories used +// in the given slice of scores +func scoreCategories(scores *[]settings.Score) []string { + catMap := make(map[string]struct{}) + for i := range *scores { + for _, cat := range (*scores)[i].Categories { + catMap[cat] = struct{}{} + } + } + categories := make([]string, 0, len(catMap)) + for cat := range catMap { + categories = append(categories, cat) + } + return categories +}