shithub: hugo

Download patch

ref: ce06bdb16a64dd39a8ebbb2e5a53b33520b00bb1
parent: 2efc1a64c391420b1007f6e94b6ff616fb136635
author: Bjørn Erik Pedersen <[email protected]>
date: Sun Dec 23 16:08:12 EST 2018

Rename CSV option from comma to delimiter

See #5555

--- a/docs/content/en/functions/transform.Unmarshal.md
+++ b/docs/content/en/functions/transform.Unmarshal.md
@@ -35,8 +35,8 @@
 
 Unmarshal with CSV as input has some options you can set:
 
-comma
-: The delmiter used, default is `,`
+delimiter
+: The delimiter used, default is `,`
 
 comment
 : The comment character ued in the CSV. If set, lines beginning with the comment character without preceding whitespace are ignored.:
--- a/hugolib/resource_chain_test.go
+++ b/hugolib/resource_chain_test.go
@@ -343,12 +343,11 @@
 			b.WithTemplates("home.html", `
 {{ $toml := "slogan = \"Hugo Rocks!\"" | resources.FromString "slogan.toml" | transform.Unmarshal }}
 {{ $csv1 := "\"Hugo Rocks\",\"Hugo is Fast!\"" | resources.FromString "slogans.csv" | transform.Unmarshal }}
-{{ $csv2 := "a;b;c" | transform.Unmarshal (dict "comma" ";") }}
+{{ $csv2 := "a;b;c" | transform.Unmarshal (dict "delimiter" ";") }}
 
 Slogan: {{ $toml.slogan }}
 CSV1: {{ $csv1 }} {{ len (index $csv1 0)  }}
-CSV2: {{ $csv2 }}
-
+CSV2: {{ $csv2 }}		
 `)
 		}, func(b *sitesBuilder) {
 			b.AssertFileContent("public/index.html",
--- a/parser/metadecoders/decoder.go
+++ b/parser/metadecoders/decoder.go
@@ -31,8 +31,8 @@
 
 // Decoder provides some configuration options for the decoders.
 type Decoder struct {
-	// Comma is the field delimiter used in the CSV decoder. It defaults to ','.
-	Comma rune
+	// Delimiter is the field delimiter used in the CSV decoder. It defaults to ','.
+	Delimiter rune
 
 	// Comment, if not 0, is the comment character ued in the CSV decoder. Lines beginning with the
 	// Comment character without preceding whitespace are ignored.
@@ -41,7 +41,7 @@
 
 // Default is a Decoder in its default configuration.
 var Default = Decoder{
-	Comma: ',',
+	Delimiter: ',',
 }
 
 // UnmarshalToMap will unmarshall data in format f into a new map. This is
@@ -156,7 +156,7 @@
 
 func (d Decoder) unmarshalCSV(data []byte, v interface{}) error {
 	r := csv.NewReader(bytes.NewReader(data))
-	r.Comma = d.Comma
+	r.Comma = d.Delimiter
 	r.Comment = d.Comment
 
 	records, err := r.ReadAll()
--- a/parser/metadecoders/format.go
+++ b/parser/metadecoders/format.go
@@ -92,7 +92,7 @@
 // in the given string.
 // It return an empty string if no format could be detected.
 func (d Decoder) FormatFromContentString(data string) Format {
-	csvIdx := strings.IndexRune(data, d.Comma)
+	csvIdx := strings.IndexRune(data, d.Delimiter)
 	jsonIdx := strings.Index(data, "{")
 	yamlIdx := strings.Index(data, ":")
 	tomlIdx := strings.Index(data, "=")
--- a/tpl/transform/unmarshal.go
+++ b/tpl/transform/unmarshal.go
@@ -116,12 +116,12 @@
 	// mapstructure does not support string to rune conversion, so do that manually.
 	// See https://github.com/mitchellh/mapstructure/issues/151
 	for k, v := range m {
-		if strings.EqualFold(k, "Comma") {
+		if strings.EqualFold(k, "Delimiter") {
 			r, err := stringToRune(v)
 			if err != nil {
 				return opts, err
 			}
-			opts.Comma = r
+			opts.Delimiter = r
 			delete(m, k)
 
 		} else if strings.EqualFold(k, "Comment") {
--- a/tpl/transform/unmarshal_test.go
+++ b/tpl/transform/unmarshal_test.go
@@ -118,7 +118,7 @@
 			assert.Equal(5, len(first))
 			assert.Equal("Ford", first[1])
 		}},
-		{testContentResource{key: "r1", content: `a;b;c`, mime: media.CSVType}, map[string]interface{}{"comma": ";"}, func(r [][]string) {
+		{testContentResource{key: "r1", content: `a;b;c`, mime: media.CSVType}, map[string]interface{}{"delimiter": ";"}, func(r [][]string) {
 			assert.Equal(r, [][]string{[]string{"a", "b", "c"}})
 
 		}},
@@ -126,13 +126,13 @@
 			assert.Equal(r, [][]string{[]string{"a", "b", "c"}})
 
 		}},
-		{"a;b;c", map[string]interface{}{"comma": ";"}, func(r [][]string) {
+		{"a;b;c", map[string]interface{}{"delimiter": ";"}, func(r [][]string) {
 			assert.Equal(r, [][]string{[]string{"a", "b", "c"}})
 
 		}},
 		{testContentResource{key: "r1", content: `
 % This is a comment
-a;b;c`, mime: media.CSVType}, map[string]interface{}{"CommA": ";", "Comment": "%"}, func(r [][]string) {
+a;b;c`, mime: media.CSVType}, map[string]interface{}{"DElimiter": ";", "Comment": "%"}, func(r [][]string) {
 			assert.Equal(r, [][]string{[]string{"a", "b", "c"}})
 
 		}},