1
0
mirror of https://github.com/go-task/task.git synced 2025-08-10 22:42:19 +02:00

Export Time Struct to Template

This commit is contained in:
Stephen Prater
2019-08-25 13:16:59 -07:00
parent cb6fe4bb59
commit a1aec8178a
11 changed files with 40 additions and 26 deletions

View File

@@ -14,12 +14,12 @@ import (
type Templater struct {
Vars taskfile.Vars
strMap map[string]string
err error
cacheMap map[string](interface{})
err error
}
func (r *Templater) RefreshStringMap() {
r.strMap = r.Vars.ToStringMap()
func (r *Templater) RefreshCacheMap() {
r.cacheMap = r.Vars.ToCacheMap()
}
func (r *Templater) Replace(str string) string {
@@ -33,12 +33,12 @@ func (r *Templater) Replace(str string) string {
return ""
}
if r.strMap == nil {
r.strMap = r.Vars.ToStringMap()
if r.cacheMap == nil {
r.cacheMap = r.Vars.ToCacheMap()
}
var b bytes.Buffer
if err = templ.Execute(&b, r.strMap); err != nil {
if err = templ.Execute(&b, r.cacheMap); err != nil {
r.err = err
return ""
}
@@ -66,6 +66,7 @@ func (r *Templater) ReplaceVars(vars taskfile.Vars) taskfile.Vars {
for k, v := range vars {
new[k] = taskfile.Var{
Static: r.Replace(v.Static),
Live: v.Live,
Sh: r.Replace(v.Sh),
}
}