Skip to content

Commit

Permalink
Merge pull request #3 from t0pep0/master
Browse files Browse the repository at this point in the history
Add Helpers
  • Loading branch information
yosssi committed Apr 3, 2014
2 parents d0650ad + 15d9bc4 commit 9f7d7e4
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions generator.go
Expand Up @@ -19,16 +19,22 @@ const (

// A generator represents an HTML generator.
type Generator struct {
cache bool
templates map[string]*template.Template
gtemplates map[string]*Template
cache bool
templates map[string]*template.Template
gtemplates map[string]*Template
helperFuncs template.FuncMap
}

// ParseFile parses a Gold template file and returns an HTML template.
func (g *Generator) ParseFile(path string) (*template.Template, error) {
return g.generateTemplate(path, nil)
}

//Set Helpers
func (g *Generator) SetHelpers(helperFuncs template.FuncMap) {
g.helperFuncs = helperFuncs
}

// ParseString parses a Gold template string and returns an HTML template.
func (g *Generator) ParseString(stringTemplates map[string]string, name string) (*template.Template, error) {
return g.generateTemplate(name, stringTemplates)
Expand All @@ -49,7 +55,9 @@ func (g *Generator) generateTemplate(path string, stringTemplates map[string]str
if err != nil {
return nil, err
}
tpl, err := template.New(path).Parse(html)
tpl := template.New(path)
tpl.Funcs(g.helperFuncs)
_, err = tpl.Parse(html)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 9f7d7e4

Please sign in to comment.