2020-02-26 05:26:43 +00:00
|
|
|
//go:generate inline -o templates.go -p cdr mixtape.tmpl templates/parts.tmpl
|
2020-02-26 05:13:51 +00:00
|
|
|
|
|
|
|
package cdr
|
|
|
|
|
|
|
|
import (
|
|
|
|
"html/template"
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
2020-02-29 16:17:48 +00:00
|
|
|
"log"
|
2020-02-26 05:13:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func Render(m *Mixtape, w io.Writer) error {
|
|
|
|
partsRawTmpl, err := ReadAsset("templates/parts.tmpl", false)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
mixtapeRawTmpl, err := ioutil.ReadFile("mixtape.tmpl")
|
|
|
|
if err != nil {
|
2020-02-29 16:17:48 +00:00
|
|
|
log.Print("Unable to load local mixtape.tmpl; falling back to default")
|
2020-02-26 05:26:43 +00:00
|
|
|
mixtapeRawTmpl, err = ReadAsset("mixtape.tmpl", false)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-02-29 16:17:48 +00:00
|
|
|
} else {
|
|
|
|
log.Print("Generating from local mixtape.tmpl")
|
2020-02-26 05:13:51 +00:00
|
|
|
}
|
|
|
|
t, err := template.New("mixtape").Parse(string(mixtapeRawTmpl) + string(partsRawTmpl))
|
|
|
|
if err != nil {
|
2020-02-29 16:17:48 +00:00
|
|
|
log.Printf("[ERROR] Unable to parse: %v", err)
|
2020-02-26 05:13:51 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-02-29 16:17:48 +00:00
|
|
|
err = t.ExecuteTemplate(w, "mixtape", m)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("[ERROR] Unable to render: %v", err)
|
|
|
|
}
|
2020-02-26 05:13:51 +00:00
|
|
|
return nil
|
|
|
|
}
|