summaryrefslogtreecommitdiffstats
path: root/hugolib/resource_chain_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-08-12 16:43:37 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-08-13 11:44:20 +0200
commitb64617fe4f90da030bcf4a9c5a4913393ce96b14 (patch)
tree07240dbf51bb4afef9ea063f2310c1617be6bb0a /hugolib/resource_chain_test.go
parent17ca8f0c4c636752fb9da2ad551679275dc03dd3 (diff)
Add resources.Match and resources.GetMatch
Fix #6190
Diffstat (limited to 'hugolib/resource_chain_test.go')
-rw-r--r--hugolib/resource_chain_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/hugolib/resource_chain_test.go b/hugolib/resource_chain_test.go
index 75f5595e1..84c871e4d 100644
--- a/hugolib/resource_chain_test.go
+++ b/hugolib/resource_chain_test.go
@@ -502,3 +502,33 @@ func TestMultiSiteResource(t *testing.T) {
b.AssertFileContent("public/text/pipes.txt", "Hugo Pipes")
}
+
+func TestResourcesMatch(t *testing.T) {
+ t.Parallel()
+
+ b := newTestSitesBuilder(t)
+
+ b.WithContent("page.md", "")
+
+ b.WithSourceFile(
+ "assets/jsons/data1.json", "json1 content",
+ "assets/jsons/data2.json", "json2 content",
+ "assets/jsons/data3.xml", "xml content",
+ )
+
+ b.WithTemplates("index.html", `
+{{ $jsons := (resources.Match "jsons/*.json") }}
+{{ $json := (resources.GetMatch "jsons/*.json") }}
+{{ printf "JSONS: %d" (len $jsons) }}
+JSON: {{ $json.RelPermalink }}: {{ $json.Content }}
+{{ range $jsons }}
+{{- .RelPermalink }}: {{ .Content }}
+{{ end }}
+`)
+
+ b.Build(BuildCfg{})
+
+ b.AssertFileContent("public/index.html",
+ "JSON: /jsons/data1.json: json1 content",
+ "JSONS: 2", "/jsons/data1.json: json1 content")
+}