media, output: Add CSV type and format

And make CSS correclty behave as plain text.
This commit is contained in:
Bjørn Erik Pedersen 2017-04-01 15:12:31 +02:00
parent 05949c9038
commit f911b107ef
4 changed files with 30 additions and 6 deletions

View file

@ -49,6 +49,7 @@ func (m Type) String() string {
var ( var (
CalendarType = Type{"text", "calendar", "ics"} CalendarType = Type{"text", "calendar", "ics"}
CSSType = Type{"text", "css", "css"} CSSType = Type{"text", "css", "css"}
CSVType = Type{"text", "csv", "csv"}
HTMLType = Type{"text", "html", "html"} HTMLType = Type{"text", "html", "html"}
JavascriptType = Type{"application", "javascript", "js"} JavascriptType = Type{"application", "javascript", "js"}
JSONType = Type{"application", "json", "json"} JSONType = Type{"application", "json", "json"}

View file

@ -30,6 +30,7 @@ func TestDefaultTypes(t *testing.T) {
}{ }{
{CalendarType, "text", "calendar", "ics", "text/calendar", "text/calendar+ics"}, {CalendarType, "text", "calendar", "ics", "text/calendar", "text/calendar+ics"},
{CSSType, "text", "css", "css", "text/css", "text/css+css"}, {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"}, {HTMLType, "text", "html", "html", "text/html", "text/html+html"},
{JavascriptType, "application", "javascript", "js", "application/javascript", "application/javascript+js"}, {JavascriptType, "application", "javascript", "js", "application/javascript", "application/javascript+js"},
{JSONType, "application", "json", "json", "application/json", "application/json+json"}, {JSONType, "application", "json", "json", "application/json", "application/json+json"},

View file

@ -43,10 +43,18 @@ var (
} }
CSSFormat = Format{ CSSFormat = Format{
Name: "CSS", Name: "CSS",
MediaType: media.CSSType, MediaType: media.CSSType,
BaseName: "styles", BaseName: "styles",
Rel: "stylesheet", IsPlainText: true,
Rel: "stylesheet",
}
CSVFormat = Format{
Name: "CSV",
MediaType: media.CSVType,
BaseName: "index",
IsPlainText: true,
Rel: "alternate",
} }
HTMLFormat = Format{ HTMLFormat = Format{

View file

@ -28,17 +28,31 @@ func TestDefaultTypes(t *testing.T) {
require.True(t, CalendarFormat.IsPlainText) require.True(t, CalendarFormat.IsPlainText)
require.False(t, CalendarFormat.IsHTML) 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, "HTML", HTMLFormat.Name)
require.Equal(t, media.HTMLType, HTMLFormat.MediaType) require.Equal(t, media.HTMLType, HTMLFormat.MediaType)
require.Empty(t, HTMLFormat.Path) 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.False(t, HTMLFormat.IsPlainText)
require.True(t, HTMLFormat.IsHTML) require.True(t, HTMLFormat.IsHTML)
require.Equal(t, "AMP", AMPFormat.Name) require.Equal(t, "AMP", AMPFormat.Name)
require.Equal(t, media.HTMLType, AMPFormat.MediaType) require.Equal(t, media.HTMLType, AMPFormat.MediaType)
require.Equal(t, "amp", AMPFormat.Path) 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.False(t, AMPFormat.IsPlainText)
require.True(t, AMPFormat.IsHTML) require.True(t, AMPFormat.IsHTML)