1
0
mirror of https://github.com/thebaer/cdr.git synced 2024-11-15 01:31:01 +00:00

Fall back to default mixtape template

if there is no mixtape.tmpl in the destination directory.
This commit is contained in:
Matt Baer 2020-02-26 00:26:43 -05:00
parent 2246bed69b
commit ef54c10c9d
2 changed files with 33 additions and 3 deletions

View File

@ -1,4 +1,4 @@
//go:generate inline -o templates.go -p cdr templates/parts.tmpl //go:generate inline -o templates.go -p cdr mixtape.tmpl templates/parts.tmpl
package cdr package cdr
@ -15,7 +15,10 @@ func Render(m *Mixtape, w io.Writer) error {
} }
mixtapeRawTmpl, err := ioutil.ReadFile("mixtape.tmpl") mixtapeRawTmpl, err := ioutil.ReadFile("mixtape.tmpl")
if err != nil { if err != nil {
return err mixtapeRawTmpl, err = ReadAsset("mixtape.tmpl", false)
if err != nil {
return err
}
} }
t, err := template.New("mixtape").Parse(string(mixtapeRawTmpl) + string(partsRawTmpl)) t, err := template.New("mixtape").Parse(string(mixtapeRawTmpl) + string(partsRawTmpl))
if err != nil { if err != nil {

View File

@ -1,4 +1,4 @@
// Code generated by "inline -o templates.go -p cdr templates/parts.tmpl" -- DO NOT EDIT -- // Code generated by "inline -o templates.go -p cdr mixtape.tmpl templates/parts.tmpl" -- DO NOT EDIT --
package cdr package cdr
@ -18,6 +18,33 @@ func ReadAsset(file string, useLocal bool) ([]byte, error) {
} }
var files = map[string]string{ var files = map[string]string{
"mixtape.tmpl": `{{define "mixtape"}}
<html>
<head>
<title>Mixtape</title>
<style type="text/css">
body {
font-size: 1.2em;
margin: 1em;
}
.active {
font-weight: bold;
}
#playlist {
list-style: none;
margin: 1em 0;
padding: 0;
}
#playlist li {
margin: 0.5em 0;
}
</style>
</head>
<body>
{{template "full-player" .Tracks}}
</body>
</html>
{{end}}`,
"templates/parts.tmpl": `{{define "player"}} "templates/parts.tmpl": `{{define "player"}}
{{with $x := index . 0}} {{with $x := index . 0}}
<audio id="player" preload="auto" tabindex="0" controls> <audio id="player" preload="auto" tabindex="0" controls>