2020-02-26 05:13:51 +00:00
|
|
|
package cdr
|
|
|
|
|
|
|
|
import (
|
2022-03-31 03:14:32 +00:00
|
|
|
_ "embed"
|
2020-02-26 05:13:51 +00:00
|
|
|
"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 {
|
|
|
|
mixtapeRawTmpl, err := ioutil.ReadFile("mixtape.tmpl")
|
|
|
|
if err != nil {
|
2022-03-31 03:14:32 +00:00
|
|
|
log.Print("Unable to load custom mixtape.tmpl; falling back to default")
|
|
|
|
mixtapeRawTmpl = defaultMixtapeTmpl
|
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
|
|
|
|
}
|