mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-21 21:35:28 +02:00
Reimplement and simplify Hugo's template system
See #13541 for details. Fixes #13545 Fixes #13515 Closes #7964 Closes #13365 Closes #12988 Closes #4891
This commit is contained in:
@@ -33,14 +33,14 @@ func TestExtractShortcodes(t *testing.T) {
|
||||
b := newTestSitesBuilder(t).WithSimpleConfigFile()
|
||||
|
||||
b.WithTemplates(
|
||||
"default/single.html", `EMPTY`,
|
||||
"_internal/shortcodes/tag.html", `tag`,
|
||||
"_internal/shortcodes/legacytag.html", `{{ $_hugo_config := "{ \"version\": 1 }" }}tag`,
|
||||
"_internal/shortcodes/sc1.html", `sc1`,
|
||||
"_internal/shortcodes/sc2.html", `sc2`,
|
||||
"_internal/shortcodes/inner.html", `{{with .Inner }}{{ . }}{{ end }}`,
|
||||
"_internal/shortcodes/inner2.html", `{{.Inner}}`,
|
||||
"_internal/shortcodes/inner3.html", `{{.Inner}}`,
|
||||
"pages/single.html", `EMPTY`,
|
||||
"shortcodes/tag.html", `tag`,
|
||||
"shortcodes/legacytag.html", `{{ $_hugo_config := "{ \"version\": 1 }" }}tag`,
|
||||
"shortcodes/sc1.html", `sc1`,
|
||||
"shortcodes/sc2.html", `sc2`,
|
||||
"shortcodes/inner.html", `{{with .Inner }}{{ . }}{{ end }}`,
|
||||
"shortcodes/inner2.html", `{{.Inner}}`,
|
||||
"shortcodes/inner3.html", `{{.Inner}}`,
|
||||
).WithContent("page.md", `---
|
||||
title: "Shortcodes Galore!"
|
||||
---
|
||||
@@ -57,10 +57,9 @@ title: "Shortcodes Galore!"
|
||||
if s == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
|
||||
var version int
|
||||
if s.info != nil {
|
||||
version = s.info.ParseInfo().Config.Version
|
||||
if s.templ != nil {
|
||||
version = s.templ.ParseInfo.Config.Version
|
||||
}
|
||||
return strReplacer.Replace(fmt.Sprintf("%s;inline:%t;closing:%t;inner:%v;params:%v;ordinal:%d;markup:%t;version:%d;pos:%d",
|
||||
s.name, s.isInline, s.isClosing, s.inner, s.params, s.ordinal, s.doMarkup, version, s.pos))
|
||||
@@ -69,7 +68,7 @@ title: "Shortcodes Galore!"
|
||||
regexpCheck := func(re string) func(c *qt.C, shortcode *shortcode, err error) {
|
||||
return func(c *qt.C, shortcode *shortcode, err error) {
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(str(shortcode), qt.Matches, ".*"+re+".*")
|
||||
c.Assert(str(shortcode), qt.Matches, ".*"+re+".*", qt.Commentf("%s", shortcode.name))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -888,6 +887,7 @@ outputs: ["html", "css", "csv", "json"]
|
||||
"_default/single.json", "{{ .Content }}",
|
||||
"shortcodes/myshort.html", `Short-HTML`,
|
||||
"shortcodes/myshort.csv", `Short-CSV`,
|
||||
"shortcodes/myshort.txt", `Short-TXT`,
|
||||
)
|
||||
|
||||
b.Build(BuildCfg{})
|
||||
@@ -897,12 +897,12 @@ outputs: ["html", "css", "csv", "json"]
|
||||
for i := range numPages {
|
||||
b.AssertFileContent(fmt.Sprintf("public/page%d/index.html", i), "Short-HTML")
|
||||
b.AssertFileContent(fmt.Sprintf("public/page%d/index.csv", i), "Short-CSV")
|
||||
b.AssertFileContent(fmt.Sprintf("public/page%d/index.json", i), "Short-HTML")
|
||||
b.AssertFileContent(fmt.Sprintf("public/page%d/index.json", i), "Short-CSV")
|
||||
|
||||
}
|
||||
|
||||
for i := range numPages {
|
||||
b.AssertFileContent(fmt.Sprintf("public/page%d/styles.css", i), "Short-HTML")
|
||||
b.AssertFileContent(fmt.Sprintf("public/page%d/styles.css", i), "Short-CSV")
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user