Skip to content

Commit

Permalink
LoadTemplates: remove excessive return value
Browse files Browse the repository at this point in the history
  • Loading branch information
seletskiy committed Aug 8, 2019
1 parent 4cfda3a commit 559b913
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
25 changes: 7 additions & 18 deletions pkg/mark/includes/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ var (
func LoadTemplate(
path string,
templates *template.Template,
) (string, *template.Template, error) {
) (*template.Template, error) {
var (
name = strings.TrimSuffix(path, filepath.Ext(path))
facts = karma.Describe("name", name)
)

if template := templates.Lookup(name); template != nil {
return name, template, nil
return template, nil
}

var body []byte
Expand All @@ -43,7 +43,7 @@ func LoadTemplate(
"unable to read template file",
)

return name, nil, err
return nil, err
}

templates, err = templates.New(name).Parse(string(body))
Expand All @@ -53,10 +53,10 @@ func LoadTemplate(
"unable to parse template",
)

return name, nil, err
return nil, err
}

return name, templates, nil
return templates, nil
}

func ProcessIncludes(
Expand Down Expand Up @@ -117,27 +117,16 @@ func ProcessIncludes(

log.Tracef(vardump(facts, data), "including template %q", path)

var name string

name, templates, err = LoadTemplate(path, templates)
templates, err = LoadTemplate(path, templates)
if err != nil {
err = facts.Format(err, "unable to load template")

return nil
}

facts = facts.Describe("name", name)

template := templates.Lookup(string(name))
if template == nil {
err = facts.Reason("template not found")

return nil
}

var buffer bytes.Buffer

err = template.Execute(&buffer, data)
err = templates.Execute(&buffer, data)
if err != nil {
err = vardump(facts, data).Format(
err,
Expand Down
4 changes: 2 additions & 2 deletions pkg/mark/macro/macro.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

var reMacroDirective = regexp.MustCompile(
`(?s)<!--\s*Macro:\s*([^\n]+)\n\s*Template:\s*(\S+)\n(.*?)-->`,
`(?s)<!--\s*Macro:\s*([^\n]+)\n\s*Template:\s*(\S+)(.*?)-->`,
)

type Macro struct {
Expand Down Expand Up @@ -111,7 +111,7 @@ func LoadMacros(
macro Macro
)

_, macro.Template, err = includes.LoadTemplate(path, templates)
macro.Template, err = includes.LoadTemplate(path, templates)

if err != nil {
err = karma.Format(err, "unable to load template")
Expand Down

0 comments on commit 559b913

Please sign in to comment.