dati

A Go library/binary to parse & execute data against template langauges.
git clone git://src.gearsix.net/dati
Log | Files | Refs | Atom | README | LICENSE

commit bf0bb315ccff85e05335085997a4ca485044a053
parent c3679058d949552863a324e24386810be2ce1225
Author: gearsix <gearsix@tuta.io>
Date:   Sun, 11 Apr 2021 15:02:48 +0100

renamed ExecuteTemplate -> Execute; Execute takes interface{} (not Data)

Diffstat:
Mcmd/suti.go | 2+-
Mtemplate.go | 2+-
Mtemplate_test.go | 28++++++++++++++--------------
3 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/cmd/suti.go b/cmd/suti.go @@ -99,7 +99,7 @@ func main() { template, err := suti.LoadTemplateFile(opts.RootPath, opts.PartialPaths...) assert(err, "unable to load templates") - out, err := template.ExecuteTemplate(super) + out, err := template.Execute(super) assert(err, "failed to execute template '%s'", opts.RootPath) fmt.Print(out.String()) diff --git a/template.go b/template.go @@ -172,7 +172,7 @@ func LoadTemplateFile(root string, partials ...string) (t Template, e error) { // Execute executes `t` against `d`. Reflection is used to determine // the template type and call it's execution fuction. -func (t *Template) Execute(d Data) (result bytes.Buffer, err error) { +func (t *Template) Execute(d interface{}) (result bytes.Buffer, err error) { tv := reflect.ValueOf(t.Template) tt := reflect.TypeOf(t.Template) diff --git a/template_test.go b/template_test.go @@ -132,7 +132,7 @@ func TestLoadTemplateFile(t *testing.T) { } } -func validateExecuteTemplate(t *testing.T, results string, expect string, e error) { +func validateExecute(t *testing.T, results string, expect string, e error) { if e != nil { t.Error(e) } else if results != expect { @@ -140,7 +140,7 @@ func validateExecuteTemplate(t *testing.T, results string, expect string, e erro } } -func TestExecuteTemplate(t *testing.T) { +func TestExecute(t *testing.T) { var e error var sd, gd, data Data var d []Data @@ -197,18 +197,18 @@ func TestExecuteTemplate(t *testing.T) { t.Skip("setup failure:", e) } - results, e = tmpl1.ExecuteTemplate(sd) - validateExecuteTemplate(t, results.String(), tmplResult, e) - results, e = tmpl2.ExecuteTemplate(sd) - validateExecuteTemplate(t, results.String(), tmplResult, e) + results, e = tmpl1.Execute(sd) + validateExecute(t, results.String(), tmplResult, e) + results, e = tmpl2.Execute(sd) + validateExecute(t, results.String(), tmplResult, e) - results, e = hmpl1.ExecuteTemplate(sd) - validateExecuteTemplate(t, results.String(), hmplResult, e) - results, e = hmpl2.ExecuteTemplate(sd) - validateExecuteTemplate(t, results.String(), tmplResult, e) + results, e = hmpl1.Execute(sd) + validateExecute(t, results.String(), hmplResult, e) + results, e = hmpl2.Execute(sd) + validateExecute(t, results.String(), tmplResult, e) - results, e = mst1.ExecuteTemplate(sd) - validateExecuteTemplate(t, results.String(), mstResult, e) - results, e = mst2.ExecuteTemplate(sd) - validateExecuteTemplate(t, results.String(), mstResult, e) + results, e = mst1.Execute(sd) + validateExecute(t, results.String(), mstResult, e) + results, e = mst2.Execute(sd) + validateExecute(t, results.String(), mstResult, e) }