From ef54c10c9dd48c64c752536a568313c4f57c82ce Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Wed, 26 Feb 2020 00:26:43 -0500 Subject: [PATCH] Fall back to default mixtape template if there is no mixtape.tmpl in the destination directory. --- render.go | 7 +++++-- templates.go | 29 ++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/render.go b/render.go index 6b389cd..114c51d 100644 --- a/render.go +++ b/render.go @@ -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 @@ -15,7 +15,10 @@ func Render(m *Mixtape, w io.Writer) error { } mixtapeRawTmpl, err := ioutil.ReadFile("mixtape.tmpl") 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)) if err != nil { diff --git a/templates.go b/templates.go index 9677590..1f89389 100644 --- a/templates.go +++ b/templates.go @@ -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 @@ -18,6 +18,33 @@ func ReadAsset(file string, useLocal bool) ([]byte, error) { } var files = map[string]string{ + "mixtape.tmpl": `{{define "mixtape"}} + + + Mixtape + + + + {{template "full-player" .Tracks}} + + +{{end}}`, "templates/parts.tmpl": `{{define "player"}} {{with $x := index . 0}}