summaryrefslogtreecommitdiff
path: root/gomplate.go
diff options
context:
space:
mode:
authorDave Henderson <dhenderson@gmail.com>2018-02-18 23:25:43 -0500
committerDave Henderson <dhenderson@gmail.com>2018-04-18 15:23:49 -0400
commit0ff06aa75c6a3062852f08c0ae73751530ede6c3 (patch)
tree01002e4c015ee950f3b63c6584ebb8462eaf9b87 /gomplate.go
parentcd60ef2d97a45135f3b4127ea0038db5a4ffe847 (diff)
Putting main pkg in cmd subdirectory
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'gomplate.go')
-rw-r--r--gomplate.go48
1 files changed, 35 insertions, 13 deletions
diff --git a/gomplate.go b/gomplate.go
index 76b06260..debfed74 100644
--- a/gomplate.go
+++ b/gomplate.go
@@ -1,4 +1,4 @@
-package main
+package gomplate
import (
"io"
@@ -7,16 +7,33 @@ import (
"github.com/hairyhenderson/gomplate/data"
)
-// Gomplate -
-type Gomplate struct {
+// Config - values necessary for rendering templates with gomplate.
+// Mainly for use by the CLI
+type Config struct {
+ Input string
+ InputFiles []string
+ InputDir string
+ ExcludeGlob []string
+ OutputFiles []string
+ OutputDir string
+
+ DataSources []string
+ DataSourceHeaders []string
+
+ LDelim string
+ RDelim string
+}
+
+// gomplate -
+type gomplate struct {
funcMap template.FuncMap
leftDelim string
rightDelim string
}
-// RunTemplate -
-func (g *Gomplate) RunTemplate(t *tplate) error {
- context := &Context{}
+// runTemplate -
+func (g *gomplate) runTemplate(t *tplate) error {
+ context := &context{}
tmpl, err := t.toGoTemplate(g)
if err != nil {
return err
@@ -31,28 +48,33 @@ func (g *Gomplate) RunTemplate(t *tplate) error {
return err
}
-// NewGomplate -
-func NewGomplate(d *data.Data, leftDelim, rightDelim string) *Gomplate {
- return &Gomplate{
+// newGomplate -
+func newGomplate(d *data.Data, leftDelim, rightDelim string) *gomplate {
+ return &gomplate{
leftDelim: leftDelim,
rightDelim: rightDelim,
funcMap: initFuncs(d),
}
}
-func runTemplate(o *GomplateOpts) error {
+// RunTemplates - run all gomplate templates specified by the given configuration
+func RunTemplates(o *Config) error {
defer runCleanupHooks()
- d := data.NewData(o.dataSources, o.dataSourceHeaders)
+ d := data.NewData(o.DataSources, o.DataSourceHeaders)
addCleanupHook(d.Cleanup)
- g := NewGomplate(d, o.lDelim, o.rDelim)
+ g := newGomplate(d, o.LDelim, o.RDelim)
+
+ return g.runTemplates(o)
+}
+func (g *gomplate) runTemplates(o *Config) error {
tmpl, err := gatherTemplates(o)
if err != nil {
return err
}
for _, t := range tmpl {
- if err := g.RunTemplate(t); err != nil {
+ if err := g.runTemplate(t); err != nil {
return err
}
}