From f911b107ef32c1c4369aa252a790e3c933660135 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sat, 1 Apr 2017 15:12:31 +0200 Subject: [PATCH] media, output: Add CSV type and format And make CSS correclty behave as plain text. --- media/mediaType.go | 1 + media/mediaType_test.go | 1 + output/outputFormat.go | 16 ++++++++++++---- output/outputFormat_test.go | 18 ++++++++++++++++-- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/media/mediaType.go b/media/mediaType.go index f6597fdb..a6ba873e 100644 --- a/media/mediaType.go +++ b/media/mediaType.go @@ -49,6 +49,7 @@ func (m Type) String() string { var ( CalendarType = Type{"text", "calendar", "ics"} CSSType = Type{"text", "css", "css"} + CSVType = Type{"text", "csv", "csv"} HTMLType = Type{"text", "html", "html"} JavascriptType = Type{"application", "javascript", "js"} JSONType = Type{"application", "json", "json"} diff --git a/media/mediaType_test.go b/media/mediaType_test.go index 7636af59..e918b939 100644 --- a/media/mediaType_test.go +++ b/media/mediaType_test.go @@ -30,6 +30,7 @@ func TestDefaultTypes(t *testing.T) { }{ {CalendarType, "text", "calendar", "ics", "text/calendar", "text/calendar+ics"}, {CSSType, "text", "css", "css", "text/css", "text/css+css"}, + {CSVType, "text", "csv", "csv", "text/csv", "text/csv+csv"}, {HTMLType, "text", "html", "html", "text/html", "text/html+html"}, {JavascriptType, "application", "javascript", "js", "application/javascript", "application/javascript+js"}, {JSONType, "application", "json", "json", "application/json", "application/json+json"}, diff --git a/output/outputFormat.go b/output/outputFormat.go index 797c7ae2..76329a93 100644 --- a/output/outputFormat.go +++ b/output/outputFormat.go @@ -43,10 +43,18 @@ var ( } CSSFormat = Format{ - Name: "CSS", - MediaType: media.CSSType, - BaseName: "styles", - Rel: "stylesheet", + Name: "CSS", + MediaType: media.CSSType, + BaseName: "styles", + IsPlainText: true, + Rel: "stylesheet", + } + CSVFormat = Format{ + Name: "CSV", + MediaType: media.CSVType, + BaseName: "index", + IsPlainText: true, + Rel: "alternate", } HTMLFormat = Format{ diff --git a/output/outputFormat_test.go b/output/outputFormat_test.go index 1d3700f4..e742012b 100644 --- a/output/outputFormat_test.go +++ b/output/outputFormat_test.go @@ -28,17 +28,31 @@ func TestDefaultTypes(t *testing.T) { require.True(t, CalendarFormat.IsPlainText) require.False(t, CalendarFormat.IsHTML) + require.Equal(t, "CSS", CSSFormat.Name) + require.Equal(t, media.CSSType, CSSFormat.MediaType) + require.Empty(t, CSSFormat.Path) + require.Empty(t, CSSFormat.Protocol) // Will inherit the BaseURL protocol. + require.True(t, CSSFormat.IsPlainText) + require.False(t, CSSFormat.IsHTML) + + require.Equal(t, "CSV", CSVFormat.Name) + require.Equal(t, media.CSVType, CSVFormat.MediaType) + require.Empty(t, CSVFormat.Path) + require.Empty(t, CSVFormat.Protocol) + require.True(t, CSVFormat.IsPlainText) + require.False(t, CSVFormat.IsHTML) + require.Equal(t, "HTML", HTMLFormat.Name) require.Equal(t, media.HTMLType, HTMLFormat.MediaType) require.Empty(t, HTMLFormat.Path) - require.Empty(t, HTMLFormat.Protocol) // Will inherit the BaseURL protocol. + require.Empty(t, HTMLFormat.Protocol) require.False(t, HTMLFormat.IsPlainText) require.True(t, HTMLFormat.IsHTML) require.Equal(t, "AMP", AMPFormat.Name) require.Equal(t, media.HTMLType, AMPFormat.MediaType) require.Equal(t, "amp", AMPFormat.Path) - require.Empty(t, AMPFormat.Protocol) // Will inherit the BaseURL protocol. + require.Empty(t, AMPFormat.Protocol) require.False(t, AMPFormat.IsPlainText) require.True(t, AMPFormat.IsHTML) -- 2.30.2