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

38 lines
887 B
Go
Raw Normal View History

//go:generate inline -o templates.go -p cdr mixtape.tmpl templates/parts.tmpl
package cdr
import (
"html/template"
"io"
"io/ioutil"
2020-02-29 16:17:48 +00:00
"log"
)
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")
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")
}
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)
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)
}
return nil
}