Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-07-01 11:43:17 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-07-02 00:10:21 +0300
commit4a3efea7efe59cd3de7d0eb352836ab395a2b6b3 (patch)
tree99185f7c06113125ea474af365dcb32f356d68ed /hugolib
parentc66dc6c74fa3bbe308ccaade8c76071b49908129 (diff)
Add support for inline partials
Fixes #7444
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/hugo_sites_build_errors_test.go5
-rw-r--r--hugolib/template_test.go80
2 files changed, 82 insertions, 3 deletions
diff --git a/hugolib/hugo_sites_build_errors_test.go b/hugolib/hugo_sites_build_errors_test.go
index d90a8b364..4de98a788 100644
--- a/hugolib/hugo_sites_build_errors_test.go
+++ b/hugolib/hugo_sites_build_errors_test.go
@@ -65,8 +65,7 @@ func TestSiteBuildErrors(t *testing.T) {
fileFixer: func(content string) string {
return strings.Replace(content, ".Title }}", ".Title }", 1)
},
- // Base templates gets parsed at build time.
- assertBuildError: func(a testSiteBuildErrorAsserter, err error) {
+ assertCreateError: func(a testSiteBuildErrorAsserter, err error) {
a.assertLineNumber(4, err)
},
},
@@ -91,7 +90,7 @@ func TestSiteBuildErrors(t *testing.T) {
a.c.Assert(fe.Position().LineNumber, qt.Equals, 5)
a.c.Assert(fe.Position().ColumnNumber, qt.Equals, 1)
a.c.Assert(fe.ChromaLexer, qt.Equals, "go-html-template")
- a.assertErrorMessage("\"layouts/foo/single.html:5:1\": parse failed: template: foo/single.html:5: unexpected \"}\" in operand", fe.Error())
+ a.assertErrorMessage("\"layouts/_default/single.html:5:1\": parse failed: template: _default/single.html.___b:5: unexpected \"}\" in operand", fe.Error())
},
},
diff --git a/hugolib/template_test.go b/hugolib/template_test.go
index 29993120d..673d91b5c 100644
--- a/hugolib/template_test.go
+++ b/hugolib/template_test.go
@@ -597,3 +597,83 @@ func collectIdentities(set map[identity.Identity]bool, provider identity.Provide
func ident(level int) string {
return strings.Repeat(" ", level)
}
+
+func TestPartialInline(t *testing.T) {
+
+ b := newTestSitesBuilder(t)
+
+ b.WithContent("p1.md", "")
+
+ b.WithTemplates(
+ "index.html", `
+
+{{ $p1 := partial "p1" . }}
+{{ $p2 := partial "p2" . }}
+
+P1: {{ $p1 }}
+P2: {{ $p2 }}
+
+{{ define "partials/p1" }}Inline: p1{{ end }}
+
+{{ define "partials/p2" }}
+{{ $value := 32 }}
+{{ return $value }}
+{{ end }}
+
+
+`,
+ )
+
+ b.CreateSites().Build(BuildCfg{})
+
+ b.AssertFileContent("public/index.html",
+ `
+P1: Inline: p1
+P2: 32`,
+ )
+
+}
+
+func TestPartialInlineBase(t *testing.T) {
+
+ b := newTestSitesBuilder(t)
+
+ b.WithContent("p1.md", "")
+
+ b.WithTemplates(
+ "baseof.html", `{{ $p3 := partial "p3" . }}P3: {{ $p3 }}
+{{ block "main" . }}{{ end }}{{ define "partials/p3" }}Inline: p3{{ end }}`,
+ "index.html", `
+{{ define "main" }}
+
+{{ $p1 := partial "p1" . }}
+{{ $p2 := partial "p2" . }}
+
+P1: {{ $p1 }}
+P2: {{ $p2 }}
+
+{{ end }}
+
+
+{{ define "partials/p1" }}Inline: p1{{ end }}
+
+{{ define "partials/p2" }}
+{{ $value := 32 }}
+{{ return $value }}
+{{ end }}
+
+
+`,
+ )
+
+ b.CreateSites().Build(BuildCfg{})
+
+ b.AssertFileContent("public/index.html",
+ `
+P1: Inline: p1
+P2: 32
+P3: Inline: p3
+`,
+ )
+
+}