mirror of
https://github.com/kovetskiy/mark.git
synced 2025-04-24 05:42:40 +08:00
LoadTemplates: remove excessive return value
This commit is contained in:
parent
4cfda3afc1
commit
559b913900
@ -24,14 +24,14 @@ var (
|
|||||||
func LoadTemplate(
|
func LoadTemplate(
|
||||||
path string,
|
path string,
|
||||||
templates *template.Template,
|
templates *template.Template,
|
||||||
) (string, *template.Template, error) {
|
) (*template.Template, error) {
|
||||||
var (
|
var (
|
||||||
name = strings.TrimSuffix(path, filepath.Ext(path))
|
name = strings.TrimSuffix(path, filepath.Ext(path))
|
||||||
facts = karma.Describe("name", name)
|
facts = karma.Describe("name", name)
|
||||||
)
|
)
|
||||||
|
|
||||||
if template := templates.Lookup(name); template != nil {
|
if template := templates.Lookup(name); template != nil {
|
||||||
return name, template, nil
|
return template, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var body []byte
|
var body []byte
|
||||||
@ -43,7 +43,7 @@ func LoadTemplate(
|
|||||||
"unable to read template file",
|
"unable to read template file",
|
||||||
)
|
)
|
||||||
|
|
||||||
return name, nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
templates, err = templates.New(name).Parse(string(body))
|
templates, err = templates.New(name).Parse(string(body))
|
||||||
@ -53,10 +53,10 @@ func LoadTemplate(
|
|||||||
"unable to parse template",
|
"unable to parse template",
|
||||||
)
|
)
|
||||||
|
|
||||||
return name, nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return name, templates, nil
|
return templates, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ProcessIncludes(
|
func ProcessIncludes(
|
||||||
@ -117,27 +117,16 @@ func ProcessIncludes(
|
|||||||
|
|
||||||
log.Tracef(vardump(facts, data), "including template %q", path)
|
log.Tracef(vardump(facts, data), "including template %q", path)
|
||||||
|
|
||||||
var name string
|
templates, err = LoadTemplate(path, templates)
|
||||||
|
|
||||||
name, templates, err = LoadTemplate(path, templates)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = facts.Format(err, "unable to load template")
|
err = facts.Format(err, "unable to load template")
|
||||||
|
|
||||||
return nil
|
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
|
var buffer bytes.Buffer
|
||||||
|
|
||||||
err = template.Execute(&buffer, data)
|
err = templates.Execute(&buffer, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = vardump(facts, data).Format(
|
err = vardump(facts, data).Format(
|
||||||
err,
|
err,
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var reMacroDirective = regexp.MustCompile(
|
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 {
|
type Macro struct {
|
||||||
@ -111,7 +111,7 @@ func LoadMacros(
|
|||||||
macro Macro
|
macro Macro
|
||||||
)
|
)
|
||||||
|
|
||||||
_, macro.Template, err = includes.LoadTemplate(path, templates)
|
macro.Template, err = includes.LoadTemplate(path, templates)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = karma.Format(err, "unable to load template")
|
err = karma.Format(err, "unable to load template")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user