-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add `generate suisa` command * Render the Suisa List * Configure margin in setlist template * docs: improve README
- Loading branch information
1 parent
1ec70b1
commit 416fa70
Showing
12 changed files
with
147 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
Copyright © 2024 Christof Laenzlinger <christof@laenzlinger.net> | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"html/template" | ||
"path/filepath" | ||
|
||
"github.com/laenzlinger/setlist/internal/config" | ||
"github.com/laenzlinger/setlist/internal/gig" | ||
convert "github.com/laenzlinger/setlist/internal/html/pdf" | ||
tmpl "github.com/laenzlinger/setlist/internal/html/template" | ||
"github.com/laenzlinger/setlist/internal/repertoire" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
//nolint:gochecknoglobals // cobra is designed like this | ||
var suisaCmd = &cobra.Command{ | ||
Use: "suisa", | ||
Short: "Generate a Suisa list", | ||
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs), | ||
Long: `Generates a Suisa list for a gig. | ||
`, | ||
Run: func(_ *cobra.Command, args []string) { | ||
err := generateSuisalist(args[0]) | ||
cobra.CheckErr(err) | ||
}, | ||
} | ||
|
||
//nolint:gochecknoinits // cobra is desigend like this | ||
func init() { | ||
generateCmd.AddCommand(suisaCmd) | ||
|
||
suisaCmd.Flags().StringSliceP("include-columns", "i", []string{"Title", "Year", "Composer", "Arranger", "Duration"}, | ||
"defines the repertoire columns to include in the output") | ||
|
||
err := viper.BindPFlag("suisa.include-columns", suisaCmd.Flags().Lookup("include-columns")) | ||
cobra.CheckErr(err) | ||
} | ||
|
||
func generateSuisalist(gigName string) error { | ||
include := viper.GetStringSlice("suisa.include-columns") | ||
band := config.NewBand() | ||
|
||
rep, err := repertoire.New(band) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
gig, err := gig.New(band, gigName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
content := rep.Filter(gig). | ||
IncludeColumns(include...). | ||
Render() | ||
|
||
data := tmpl.Data{ | ||
Title: gig.Name, | ||
Margin: "1cm", | ||
Content: template.HTML(content), //nolint: gosec // not a web application | ||
} | ||
|
||
filename, err := tmpl.CreateSetlist(&data) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return convert.HTMLToPDF(filename, filepath.Join(config.Target(), fmt.Sprintf("Suisa List %s.pdf", gig.Name))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ func init() { | |
|
||
type Data struct { | ||
Title string | ||
Margin string | ||
Content template.HTML | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package repertoire | ||
|
||
import "github.com/yuin/goldmark/ast" | ||
|
||
type indexes map[int]bool | ||
|
||
func removeCols(idx indexes, row ast.Node) ast.Node { | ||
i := 0 | ||
toRemove := []ast.Node{} | ||
for r := row.FirstChild(); r != nil; r = r.NextSibling() { | ||
if idx[i] { | ||
toRemove = append(toRemove, r) | ||
} | ||
i++ | ||
} | ||
for _, r := range toRemove { | ||
row.RemoveChild(row, r) | ||
} | ||
return row | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
|
||
| Title | Year | Copyright | Description | | ||
|-----------------------|------|----------------------|-------------------| | ||
| On the Alamo | 1922 | Public Domain | Lyrics: Gus Kahn | | ||
| Frankie and Johnnie | 1904 | Hughie Cannon | | | ||
| Nowhere to go | 2024 | Christof Laenzlinger | Instrumental | | ||
| Title | Year | Description | Composer | Arranger | Duration | | ||
|-----------------------|------|-------------------|------------------|----------------|----------| | ||
| On the Alamo | 1922 | Lyrics: Gus Kahn | Isham Jones | Chris Lae | 3m 2s | | ||
| Frankie and Johnnie | 1904 | | Hughie Cannon | Chris Lae | 2m 30s | | ||
| Nowhere to go | 2024 | Instrumental | Chris Lae | Chris Lae | 7m | | ||
|