mirror of
https://github.com/kovetskiy/mark.git
synced 2025-06-08 23:42:40 +08:00
small style fixes related to templates
This commit is contained in:
parent
78345736d5
commit
1ebb29eba0
@ -20,9 +20,9 @@ import (
|
|||||||
// <optional yaml data> -->
|
// <optional yaml data> -->
|
||||||
var reIncludeDirective = regexp.MustCompile(
|
var reIncludeDirective = regexp.MustCompile(
|
||||||
`(?s)` +
|
`(?s)` +
|
||||||
`<!--\s*Include:\s*(?P<template>.+?)\s*` +
|
`<!--\s*Include:\s*(?P<template>.+?)\s*` +
|
||||||
`(?:\n\s*Delims:\s*(?:(none|"(?P<left>.*?)"\s*,\s*"(?P<right>.*?)")))?\s*` +
|
`(?:\n\s*Delims:\s*(?:(none|"(?P<left>.*?)"\s*,\s*"(?P<right>.*?)")))?\s*` +
|
||||||
`(?:\n(?P<config>.*?))?-->`,
|
`(?:\n(?P<config>.*?))?-->`,
|
||||||
)
|
)
|
||||||
|
|
||||||
func LoadTemplate(
|
func LoadTemplate(
|
||||||
@ -111,15 +111,21 @@ func ProcessIncludes(
|
|||||||
groups := reIncludeDirective.FindSubmatch(spec)
|
groups := reIncludeDirective.FindSubmatch(spec)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
path, none, left, right, config = string(groups[1]), string(groups[2]), string(groups[3]), string(groups[4]), groups[5]
|
path = string(groups[1])
|
||||||
data = map[string]interface{}{}
|
delimsNone = string(groups[2])
|
||||||
|
left = string(groups[3])
|
||||||
|
right = string(groups[4])
|
||||||
|
config = groups[5]
|
||||||
|
data = map[string]interface{}{}
|
||||||
|
|
||||||
facts = karma.Describe("path", path)
|
facts = karma.Describe("path", path)
|
||||||
)
|
)
|
||||||
if none == "none" {
|
|
||||||
|
if delimsNone == "none" {
|
||||||
left = "\x00"
|
left = "\x00"
|
||||||
right = "\x01"
|
right = "\x01"
|
||||||
}
|
}
|
||||||
|
|
||||||
err = yaml.Unmarshal(config, &data)
|
err = yaml.Unmarshal(config, &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = facts.
|
err = facts.
|
||||||
|
@ -130,10 +130,10 @@ func ExtractMacros(
|
|||||||
"template",
|
"template",
|
||||||
)
|
)
|
||||||
config = regexputil.Subexp(reMacroDirective, groups, "config")
|
config = regexputil.Subexp(reMacroDirective, groups, "config")
|
||||||
|
|
||||||
macro Macro
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var macro Macro
|
||||||
|
|
||||||
if strings.HasPrefix(template, "#") {
|
if strings.HasPrefix(template, "#") {
|
||||||
cfg := map[string]interface{}{}
|
cfg := map[string]interface{}{}
|
||||||
|
|
||||||
@ -143,27 +143,38 @@ func ExtractMacros(
|
|||||||
err,
|
err,
|
||||||
"unable to unmarshal macros config template",
|
"unable to unmarshal macros config template",
|
||||||
)
|
)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
body, _ := cfg[template[1:]].(string)
|
|
||||||
|
body, ok := cfg[template[1:]].(string)
|
||||||
|
if !ok {
|
||||||
|
err = fmt.Errorf(
|
||||||
|
"the template config doesn't have '%s' field",
|
||||||
|
template[1:],
|
||||||
|
)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
macro.Template, err = templates.New(template).Parse(body)
|
macro.Template, err = templates.New(template).Parse(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = karma.Format(
|
err = karma.Format(
|
||||||
err,
|
err,
|
||||||
"unable to parse template",
|
"unable to parse template",
|
||||||
)
|
)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
macro.Template, err = includes.LoadTemplate(base, template, "{{", "}}", templates)
|
macro.Template, err = includes.LoadTemplate(base, template, "{{", "}}", templates)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = karma.Format(err, "unable to load template")
|
err = karma.Format(err, "unable to load template")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
facts := karma.
|
facts := karma.
|
||||||
Describe("template", template).
|
Describe("template", template).
|
||||||
Describe("expr", expr)
|
Describe("expr", expr)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user