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
path: root/tpl
diff options
context:
space:
mode:
authorPaul van Brouwershaven <vanbroup@users.noreply.github.com>2021-12-02 19:30:36 +0300
committerGitHub <noreply@github.com>2021-12-02 19:30:36 +0300
commit0eaaa8fee37068bfc8ecfb760f770ecc9a7af22a (patch)
tree95cf7c5ac3a7e56c0eb411a28cae5c0412a510bd /tpl
parent58adbeef88ea5c8769d12ba27eef2d89bdf575eb (diff)
Implement XML data support
Example: ``` {{ with resources.Get "https://example.com/rss.xml" | transform.Unmarshal }} {{ range .channel.item }} <strong>{{ .title | plainify | htmlUnescape }}</strong><br /> <p>{{ .description | plainify | htmlUnescape }}</p> {{ $link := .link | plainify | htmlUnescape }} <a href="{{ $link }}">{{ $link }}</a><br /> <hr> {{ end }} {{ end }} ``` Closes #4470
Diffstat (limited to 'tpl')
-rw-r--r--tpl/transform/remarshal_test.go20
-rw-r--r--tpl/transform/unmarshal_test.go3
2 files changed, 23 insertions, 0 deletions
diff --git a/tpl/transform/remarshal_test.go b/tpl/transform/remarshal_test.go
index 2cb4c3a2f..8e94ef6bf 100644
--- a/tpl/transform/remarshal_test.go
+++ b/tpl/transform/remarshal_test.go
@@ -82,6 +82,25 @@ title: Test Metadata
"title": "Test Metadata"
}
`
+ xmlExample := `<root>
+ <resources>
+ <params>
+ <byline>picasso</byline>
+ </params>
+ <src>**image-4.png</src>
+ <title>The Fourth Image!</title>
+ </resources>
+ <resources>
+ <name>my-cool-image-:counter</name>
+ <params>
+ <byline>bep</byline>
+ </params>
+ <src>**.png</src>
+ <title>TOML: The Image #:counter</title>
+ </resources>
+ <title>Test Metadata</title>
+ </root>
+ `
variants := []struct {
format string
@@ -93,6 +112,7 @@ title: Test Metadata
{"TOML", tomlExample},
{"Toml", tomlExample},
{" TOML ", tomlExample},
+ {"XML", xmlExample},
}
for _, v1 := range variants {
diff --git a/tpl/transform/unmarshal_test.go b/tpl/transform/unmarshal_test.go
index 85e3610d1..fb0e446c3 100644
--- a/tpl/transform/unmarshal_test.go
+++ b/tpl/transform/unmarshal_test.go
@@ -111,6 +111,9 @@ func TestUnmarshal(t *testing.T) {
{testContentResource{key: "r1", content: `slogan = "Hugo Rocks!"`, mime: media.TOMLType}, nil, func(m map[string]interface{}) {
assertSlogan(m)
}},
+ {testContentResource{key: "r1", content: `<root><slogan>Hugo Rocks!</slogan></root>"`, mime: media.XMLType}, nil, func(m map[string]interface{}) {
+ assertSlogan(m)
+ }},
{testContentResource{key: "r1", content: `1997,Ford,E350,"ac, abs, moon",3000.00
1999,Chevy,"Venture ""Extended Edition""","",4900.00`, mime: media.CSVType}, nil, func(r [][]string) {
c.Assert(len(r), qt.Equals, 2)