mirror of
https://github.com/kovetskiy/mark.git
synced 2025-04-23 21:32:41 +08:00
LoadTemplates: remove excessive return value
This commit is contained in:
parent
4cfda3afc1
commit
559b913900
@ -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
|
||||
@ -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))
|
||||
@ -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(
|
||||
@ -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,
|
||||
|
@ -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 {
|
||||
@ -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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user