Sort scores according to their names for the book
This commit is contained in:
parent
fb554304e3
commit
16d44f6eb3
@ -68,6 +68,8 @@ var bookTempl = `
|
|||||||
func MakeBook(path string, opts *settings.Settings) {
|
func MakeBook(path string, opts *settings.Settings) {
|
||||||
// Everything needs to be compiled
|
// Everything needs to be compiled
|
||||||
CompileDir(path, opts)
|
CompileDir(path, opts)
|
||||||
|
// Sort scores
|
||||||
|
sort.Sort(settings.ScoresByName{scores})
|
||||||
// Compile the book template
|
// Compile the book template
|
||||||
var templ = template.Must(template.New("songBook").Funcs(template.FuncMap{
|
var templ = template.Must(template.New("songBook").Funcs(template.FuncMap{
|
||||||
"in": helpers.InSlice,
|
"in": helpers.InSlice,
|
||||||
|
@ -127,3 +127,25 @@ func (s *Score) GenerateOutputPath(opts *Settings) {
|
|||||||
file = file[:dot+1] + "pdf"
|
file = file[:dot+1] + "pdf"
|
||||||
s.OutputPath = filepath.Join(opts.OutputDir, file)
|
s.OutputPath = filepath.Join(opts.OutputDir, file)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Scores aliases a slice of scores
|
||||||
|
type Scores []Score
|
||||||
|
|
||||||
|
// ScoresByName implements sort.Interface by providing Less and using the Len and
|
||||||
|
// Swap methods of the embedded Scores value.
|
||||||
|
type ScoresByName struct{ Scores }
|
||||||
|
|
||||||
|
// Len returns the number of scores and
|
||||||
|
// implements part of the sort.Interface
|
||||||
|
func (s Scores) Len() int { return len(s) }
|
||||||
|
|
||||||
|
// Swap interchanges the position of two scores and
|
||||||
|
// implements part of the sort.Interface
|
||||||
|
func (s Scores) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||||
|
|
||||||
|
// Less reports whether the name of the score on position i is
|
||||||
|
// smaller than the name of the score on position j
|
||||||
|
// and implements part of the sort.Interface
|
||||||
|
func (s ScoresByName) Less(i, j int) bool {
|
||||||
|
return s.Scores[i].Name < s.Scores[j].Name
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user