output: Rename HTMLType etc. to HTMLFormat

This commit is contained in:
Bjørn Erik Pedersen 2017-03-25 19:36:50 +01:00
parent 24c1770288
commit 09c88e84d1
11 changed files with 86 additions and 91 deletions

View file

@ -317,7 +317,6 @@ func (p *PathSpec) PrependBasePath(rel string) string {
// URLizeAndPrep applies misc sanitation to the given URL to get it in line // URLizeAndPrep applies misc sanitation to the given URL to get it in line
// with the Hugo standard. // with the Hugo standard.
// TODO(bep) output check usage
func (p *PathSpec) URLizeAndPrep(in string) string { func (p *PathSpec) URLizeAndPrep(in string) string {
return p.URLPrep(p.URLize(in)) return p.URLPrep(p.URLize(in))
} }

View file

@ -212,7 +212,7 @@ type Page struct {
} }
func (p *Page) RSSLink() template.URL { func (p *Page) RSSLink() template.URL {
f, found := p.outputFormats.GetByName(output.RSSType.Name) f, found := p.outputFormats.GetByName(output.RSSFormat.Name)
if !found { if !found {
return "" return ""
} }

View file

@ -37,88 +37,88 @@ func TestPageTargetPath(t *testing.T) {
d targetPathDescriptor d targetPathDescriptor
expected string expected string
}{ }{
{"JSON home", targetPathDescriptor{Kind: KindHome, Type: output.JSONType}, "/index.json"}, {"JSON home", targetPathDescriptor{Kind: KindHome, Type: output.JSONFormat}, "/index.json"},
{"AMP home", targetPathDescriptor{Kind: KindHome, Type: output.AMPType}, "/amp/index.html"}, {"AMP home", targetPathDescriptor{Kind: KindHome, Type: output.AMPFormat}, "/amp/index.html"},
{"HTML home", targetPathDescriptor{Kind: KindHome, BaseName: "_index", Type: output.HTMLType}, "/index.html"}, {"HTML home", targetPathDescriptor{Kind: KindHome, BaseName: "_index", Type: output.HTMLFormat}, "/index.html"},
{"HTML section list", targetPathDescriptor{ {"HTML section list", targetPathDescriptor{
Kind: KindSection, Kind: KindSection,
Sections: []string{"sect1"}, Sections: []string{"sect1"},
BaseName: "_index", BaseName: "_index",
Type: output.HTMLType}, "/sect1/index.html"}, Type: output.HTMLFormat}, "/sect1/index.html"},
{"HTML taxonomy list", targetPathDescriptor{ {"HTML taxonomy list", targetPathDescriptor{
Kind: KindTaxonomy, Kind: KindTaxonomy,
Sections: []string{"tags", "hugo"}, Sections: []string{"tags", "hugo"},
BaseName: "_index", BaseName: "_index",
Type: output.HTMLType}, "/tags/hugo/index.html"}, Type: output.HTMLFormat}, "/tags/hugo/index.html"},
{"HTML taxonomy term", targetPathDescriptor{ {"HTML taxonomy term", targetPathDescriptor{
Kind: KindTaxonomy, Kind: KindTaxonomy,
Sections: []string{"tags"}, Sections: []string{"tags"},
BaseName: "_index", BaseName: "_index",
Type: output.HTMLType}, "/tags/index.html"}, Type: output.HTMLFormat}, "/tags/index.html"},
{ {
"HTML page", targetPathDescriptor{ "HTML page", targetPathDescriptor{
Kind: KindPage, Kind: KindPage,
Dir: "/a/b", Dir: "/a/b",
BaseName: "mypage", BaseName: "mypage",
Sections: []string{"a"}, Sections: []string{"a"},
Type: output.HTMLType}, "/a/b/mypage/index.html"}, Type: output.HTMLFormat}, "/a/b/mypage/index.html"},
{ {
"HTML page with special chars", targetPathDescriptor{ "HTML page with special chars", targetPathDescriptor{
Kind: KindPage, Kind: KindPage,
Dir: "/a/b", Dir: "/a/b",
BaseName: "My Page!", BaseName: "My Page!",
Type: output.HTMLType}, "/a/b/My-Page/index.html"}, Type: output.HTMLFormat}, "/a/b/My-Page/index.html"},
{"RSS home", targetPathDescriptor{Kind: kindRSS, Type: output.RSSType}, "/index.xml"}, {"RSS home", targetPathDescriptor{Kind: kindRSS, Type: output.RSSFormat}, "/index.xml"},
{"RSS section list", targetPathDescriptor{ {"RSS section list", targetPathDescriptor{
Kind: kindRSS, Kind: kindRSS,
Sections: []string{"sect1"}, Sections: []string{"sect1"},
Type: output.RSSType}, "/sect1/index.xml"}, Type: output.RSSFormat}, "/sect1/index.xml"},
{ {
"AMP page", targetPathDescriptor{ "AMP page", targetPathDescriptor{
Kind: KindPage, Kind: KindPage,
Dir: "/a/b/c", Dir: "/a/b/c",
BaseName: "myamp", BaseName: "myamp",
Type: output.AMPType}, "/amp/a/b/c/myamp/index.html"}, Type: output.AMPFormat}, "/amp/a/b/c/myamp/index.html"},
{ {
"AMP page with URL with suffix", targetPathDescriptor{ "AMP page with URL with suffix", targetPathDescriptor{
Kind: KindPage, Kind: KindPage,
Dir: "/sect/", Dir: "/sect/",
BaseName: "mypage", BaseName: "mypage",
URL: "/some/other/url.xhtml", URL: "/some/other/url.xhtml",
Type: output.HTMLType}, "/some/other/url.xhtml"}, Type: output.HTMLFormat}, "/some/other/url.xhtml"},
{ {
"JSON page with URL without suffix", targetPathDescriptor{ "JSON page with URL without suffix", targetPathDescriptor{
Kind: KindPage, Kind: KindPage,
Dir: "/sect/", Dir: "/sect/",
BaseName: "mypage", BaseName: "mypage",
URL: "/some/other/path/", URL: "/some/other/path/",
Type: output.JSONType}, "/some/other/path/index.json"}, Type: output.JSONFormat}, "/some/other/path/index.json"},
{ {
"JSON page with URL without suffix and no trailing slash", targetPathDescriptor{ "JSON page with URL without suffix and no trailing slash", targetPathDescriptor{
Kind: KindPage, Kind: KindPage,
Dir: "/sect/", Dir: "/sect/",
BaseName: "mypage", BaseName: "mypage",
URL: "/some/other/path", URL: "/some/other/path",
Type: output.JSONType}, "/some/other/path/index.json"}, Type: output.JSONFormat}, "/some/other/path/index.json"},
{ {
"HTML page with expanded permalink", targetPathDescriptor{ "HTML page with expanded permalink", targetPathDescriptor{
Kind: KindPage, Kind: KindPage,
Dir: "/a/b", Dir: "/a/b",
BaseName: "mypage", BaseName: "mypage",
ExpandedPermalink: "/2017/10/my-title", ExpandedPermalink: "/2017/10/my-title",
Type: output.HTMLType}, "/2017/10/my-title/index.html"}, Type: output.HTMLFormat}, "/2017/10/my-title/index.html"},
{ {
"Paginated HTML home", targetPathDescriptor{ "Paginated HTML home", targetPathDescriptor{
Kind: KindHome, Kind: KindHome,
BaseName: "_index", BaseName: "_index",
Type: output.HTMLType, Type: output.HTMLFormat,
Addends: "page/3"}, "/page/3/index.html"}, Addends: "page/3"}, "/page/3/index.html"},
{ {
"Paginated Taxonomy list", targetPathDescriptor{ "Paginated Taxonomy list", targetPathDescriptor{
Kind: KindTaxonomy, Kind: KindTaxonomy,
BaseName: "_index", BaseName: "_index",
Sections: []string{"tags", "hugo"}, Sections: []string{"tags", "hugo"},
Type: output.HTMLType, Type: output.HTMLFormat,
Addends: "page/3"}, "/tags/hugo/page/3/index.html"}, Addends: "page/3"}, "/tags/hugo/page/3/index.html"},
{ {
"Regular page with addend", targetPathDescriptor{ "Regular page with addend", targetPathDescriptor{
@ -126,7 +126,7 @@ func TestPageTargetPath(t *testing.T) {
Dir: "/a/b", Dir: "/a/b",
BaseName: "mypage", BaseName: "mypage",
Addends: "c/d/e", Addends: "c/d/e",
Type: output.HTMLType}, "/a/b/mypage/c/d/e/index.html"}, Type: output.HTMLFormat}, "/a/b/mypage/c/d/e/index.html"},
} }
for i, test := range tests { for i, test := range tests {

View file

@ -218,12 +218,12 @@ func TestPaginationURLFactory(t *testing.T) {
expected string expected string
}{ }{
{"HTML home page 32", {"HTML home page 32",
targetPathDescriptor{Kind: KindHome, Type: output.HTMLType}, "http://example.com/", 32, "/zoo/32/"}, targetPathDescriptor{Kind: KindHome, Type: output.HTMLFormat}, "http://example.com/", 32, "/zoo/32/"},
{"JSON home page 42", {"JSON home page 42",
targetPathDescriptor{Kind: KindHome, Type: output.JSONType}, "http://example.com/", 42, "/zoo/42/"}, targetPathDescriptor{Kind: KindHome, Type: output.JSONFormat}, "http://example.com/", 42, "/zoo/42/"},
// Issue #1252 // Issue #1252
{"BaseURL with sub path", {"BaseURL with sub path",
targetPathDescriptor{Kind: KindHome, Type: output.HTMLType}, "http://example.com/sub/", 999, "/sub/zoo/999/"}, targetPathDescriptor{Kind: KindHome, Type: output.HTMLFormat}, "http://example.com/sub/", 999, "/sub/zoo/999/"},
} }
for _, test := range tests { for _, test := range tests {
@ -282,8 +282,8 @@ func doTestPaginator(t *testing.T, useViper bool) {
require.NoError(t, err) require.NoError(t, err)
pages := createTestPages(s, 12) pages := createTestPages(s, 12)
n1, _ := newPageOutput(s.newHomePage(), false, output.HTMLType) n1, _ := newPageOutput(s.newHomePage(), false, output.HTMLFormat)
n2, _ := newPageOutput(s.newHomePage(), false, output.HTMLType) n2, _ := newPageOutput(s.newHomePage(), false, output.HTMLFormat)
n1.Data["Pages"] = pages n1.Data["Pages"] = pages
var paginator1 *Pager var paginator1 *Pager
@ -309,7 +309,7 @@ func doTestPaginator(t *testing.T, useViper bool) {
require.Equal(t, paginator1, samePaginator) require.Equal(t, paginator1, samePaginator)
pp, _ := s.NewPage("test") pp, _ := s.NewPage("test")
p, _ := newPageOutput(pp, false, output.HTMLType) p, _ := newPageOutput(pp, false, output.HTMLFormat)
_, err = p.Paginator() _, err = p.Paginator()
require.NotNil(t, err) require.NotNil(t, err)
@ -318,7 +318,7 @@ func doTestPaginator(t *testing.T, useViper bool) {
func TestPaginatorWithNegativePaginate(t *testing.T) { func TestPaginatorWithNegativePaginate(t *testing.T) {
t.Parallel() t.Parallel()
s := newTestSite(t, "paginate", -1) s := newTestSite(t, "paginate", -1)
n1, _ := newPageOutput(s.newHomePage(), false, output.HTMLType) n1, _ := newPageOutput(s.newHomePage(), false, output.HTMLFormat)
_, err := n1.Paginator() _, err := n1.Paginator()
require.Error(t, err) require.Error(t, err)
} }
@ -381,8 +381,8 @@ func doTestPaginate(t *testing.T, useViper bool) {
} }
pages := createTestPages(s, 6) pages := createTestPages(s, 6)
n1, _ := newPageOutput(s.newHomePage(), false, output.HTMLType) n1, _ := newPageOutput(s.newHomePage(), false, output.HTMLFormat)
n2, _ := newPageOutput(s.newHomePage(), false, output.HTMLType) n2, _ := newPageOutput(s.newHomePage(), false, output.HTMLFormat)
var paginator1, paginator2 *Pager var paginator1, paginator2 *Pager
@ -407,7 +407,7 @@ func doTestPaginate(t *testing.T, useViper bool) {
require.Equal(t, paginator2, paginator1.Next()) require.Equal(t, paginator2, paginator1.Next())
pp, err := s.NewPage("test") pp, err := s.NewPage("test")
p, _ := newPageOutput(pp, false, output.HTMLType) p, _ := newPageOutput(pp, false, output.HTMLFormat)
_, err = p.Paginate(pages) _, err = p.Paginate(pages)
require.NotNil(t, err) require.NotNil(t, err)
@ -416,7 +416,7 @@ func doTestPaginate(t *testing.T, useViper bool) {
func TestInvalidOptions(t *testing.T) { func TestInvalidOptions(t *testing.T) {
t.Parallel() t.Parallel()
s := newTestSite(t) s := newTestSite(t)
n1, _ := newPageOutput(s.newHomePage(), false, output.HTMLType) n1, _ := newPageOutput(s.newHomePage(), false, output.HTMLFormat)
_, err := n1.Paginate(createTestPages(s, 1), 1, 2) _, err := n1.Paginate(createTestPages(s, 1), 1, 2)
require.NotNil(t, err) require.NotNil(t, err)
@ -434,7 +434,7 @@ func TestPaginateWithNegativePaginate(t *testing.T) {
s, err := NewSiteForCfg(deps.DepsCfg{Cfg: cfg, Fs: fs}) s, err := NewSiteForCfg(deps.DepsCfg{Cfg: cfg, Fs: fs})
require.NoError(t, err) require.NoError(t, err)
n, _ := newPageOutput(s.newHomePage(), false, output.HTMLType) n, _ := newPageOutput(s.newHomePage(), false, output.HTMLFormat)
_, err = n.Paginate(createTestPages(s, 2)) _, err = n.Paginate(createTestPages(s, 2))
require.NotNil(t, err) require.NotNil(t, err)
@ -445,7 +445,7 @@ func TestPaginatePages(t *testing.T) {
s := newTestSite(t) s := newTestSite(t)
groups, _ := createTestPages(s, 31).GroupBy("Weight", "desc") groups, _ := createTestPages(s, 31).GroupBy("Weight", "desc")
pd := targetPathDescriptor{Kind: KindHome, Type: output.HTMLType, PathSpec: s.PathSpec, Addends: "t"} pd := targetPathDescriptor{Kind: KindHome, Type: output.HTMLFormat, PathSpec: s.PathSpec, Addends: "t"}
for i, seq := range []interface{}{createTestPages(s, 11), groups, WeightedPages{}, PageGroup{}, &Pages{}} { for i, seq := range []interface{}{createTestPages(s, 11), groups, WeightedPages{}, PageGroup{}, &Pages{}} {
v, err := paginatePages(pd, seq, 11) v, err := paginatePages(pd, seq, 11)
@ -461,8 +461,8 @@ func TestPaginatePages(t *testing.T) {
func TestPaginatorFollowedByPaginateShouldFail(t *testing.T) { func TestPaginatorFollowedByPaginateShouldFail(t *testing.T) {
t.Parallel() t.Parallel()
s := newTestSite(t, "paginate", 10) s := newTestSite(t, "paginate", 10)
n1, _ := newPageOutput(s.newHomePage(), false, output.HTMLType) n1, _ := newPageOutput(s.newHomePage(), false, output.HTMLFormat)
n2, _ := newPageOutput(s.newHomePage(), false, output.HTMLType) n2, _ := newPageOutput(s.newHomePage(), false, output.HTMLFormat)
_, err := n1.Paginator() _, err := n1.Paginator()
require.Nil(t, err) require.Nil(t, err)
@ -478,8 +478,8 @@ func TestPaginateFollowedByDifferentPaginateShouldFail(t *testing.T) {
t.Parallel() t.Parallel()
s := newTestSite(t, "paginate", 10) s := newTestSite(t, "paginate", 10)
n1, _ := newPageOutput(s.newHomePage(), false, output.HTMLType) n1, _ := newPageOutput(s.newHomePage(), false, output.HTMLFormat)
n2, _ := newPageOutput(s.newHomePage(), false, output.HTMLType) n2, _ := newPageOutput(s.newHomePage(), false, output.HTMLFormat)
p1 := createTestPages(s, 2) p1 := createTestPages(s, 2)
p2 := createTestPages(s, 10) p2 := createTestPages(s, 10)

View file

@ -33,7 +33,6 @@ func createSiteOutputFormats(cfg config.Provider) (map[string]output.Formats, er
outputs := cfg.GetStringMap("outputs") outputs := cfg.GetStringMap("outputs")
if outputs == nil || len(outputs) == 0 { if outputs == nil || len(outputs) == 0 {
// TODO(bep) outputs log a warning?
return outFormats, nil return outFormats, nil
} }
@ -56,7 +55,7 @@ func createSiteOutputFormats(cfg config.Provider) (map[string]output.Formats, er
// Make sure every kind has at least one output format // Make sure every kind has at least one output format
for _, kind := range allKinds { for _, kind := range allKinds {
if _, found := outFormats[kind]; !found { if _, found := outFormats[kind]; !found {
outFormats[kind] = output.Formats{output.HTMLType} outFormats[kind] = output.Formats{output.HTMLFormat}
} }
} }
@ -69,7 +68,7 @@ func createDefaultOutputFormats(cfg config.Provider) (map[string]output.Formats,
for _, kind := range allKinds { for _, kind := range allKinds {
var formats output.Formats var formats output.Formats
// All have HTML // All have HTML
formats = append(formats, output.HTMLType) formats = append(formats, output.HTMLFormat)
// All but page have RSS // All but page have RSS
if kind != KindPage { if kind != KindPage {
@ -81,7 +80,7 @@ func createDefaultOutputFormats(cfg config.Provider) (map[string]output.Formats,
// RSS has now a well defined media type, so strip any suffix provided // RSS has now a well defined media type, so strip any suffix provided
rssBase = strings.TrimSuffix(rssBase, path.Ext(rssBase)) rssBase = strings.TrimSuffix(rssBase, path.Ext(rssBase))
rssType := output.RSSType rssType := output.RSSFormat
rssType.BaseName = rssBase rssType.BaseName = rssBase
formats = append(formats, rssType) formats = append(formats, rssType)

View file

@ -38,8 +38,8 @@ func TestDefaultOutputFormats(t *testing.T) {
kind string kind string
want output.Formats want output.Formats
}{ }{
{"RSS not for regular pages", KindPage, output.Formats{output.HTMLType}}, {"RSS not for regular pages", KindPage, output.Formats{output.HTMLFormat}},
{"Home Sweet Home", KindHome, output.Formats{output.HTMLType, output.RSSType}}, {"Home Sweet Home", KindHome, output.Formats{output.HTMLFormat, output.RSSFormat}},
} }
for _, tt := range tests { for _, tt := range tests {
@ -59,7 +59,6 @@ func TestSiteWithPageOutputs(t *testing.T) {
} }
} }
// TODO(bep) output add test for site outputs config
func doTestSiteWithPageOutputs(t *testing.T, outputs []string) { func doTestSiteWithPageOutputs(t *testing.T, outputs []string) {
t.Parallel() t.Parallel()
@ -147,7 +146,6 @@ Output/Rel: {{ .Name -}}/{{ .Rel }}|
require.Equal(t, "http://example.com/blog/index.json", json.Permalink()) require.Equal(t, "http://example.com/blog/index.json", json.Permalink())
if helpers.InStringArray(outputs, "cal") { if helpers.InStringArray(outputs, "cal") {
// TODO(bep) output have do some protocil handling for the default too if set.
cal := of.Get("calendar") cal := of.Get("calendar")
require.NotNil(t, cal) require.NotNil(t, cal)
require.Equal(t, "/blog/index.ics", cal.RelPermalink()) require.Equal(t, "/blog/index.ics", cal.RelPermalink())

View file

@ -102,7 +102,7 @@ func (l *LayoutHandler) For(d LayoutDescriptor, layoutOverride string, f Format)
layout = layoutOverride layout = layoutOverride
} }
isRSS := f.Name == RSSType.Name isRSS := f.Name == RSSFormat.Name
if d.Kind == "page" { if d.Kind == "page" {
if isRSS { if isRSS {

View file

@ -34,7 +34,6 @@ type TemplateNames struct {
MasterFilename string MasterFilename string
} }
// TODO(bep) output this is refactoring in progress.
type TemplateLookupDescriptor struct { type TemplateLookupDescriptor struct {
// The full path to the site or theme root. // The full path to the site or theme root.
WorkingDir string WorkingDir string

View file

@ -56,13 +56,13 @@ func TestLayout(t *testing.T) {
{"Page with overridden layout", LayoutDescriptor{Kind: "page", Layout: "mylayout", Type: "myttype"}, false, "myotherlayout", ampType, {"Page with overridden layout", LayoutDescriptor{Kind: "page", Layout: "mylayout", Type: "myttype"}, false, "myotherlayout", ampType,
[]string{"myttype/myotherlayout.amp.html", "myttype/myotherlayout.html"}}, []string{"myttype/myotherlayout.amp.html", "myttype/myotherlayout.html"}},
// RSS // RSS
{"RSS Home with theme", LayoutDescriptor{Kind: "home"}, true, "", RSSType, {"RSS Home with theme", LayoutDescriptor{Kind: "home"}, true, "", RSSFormat,
[]string{"rss.xml", "_default/rss.xml", "theme/rss.xml", "theme/_default/rss.xml", "_internal/_default/rss.xml"}}, []string{"rss.xml", "_default/rss.xml", "theme/rss.xml", "theme/_default/rss.xml", "_internal/_default/rss.xml"}},
{"RSS Section", LayoutDescriptor{Kind: "section", Section: "sect1"}, false, "", RSSType, {"RSS Section", LayoutDescriptor{Kind: "section", Section: "sect1"}, false, "", RSSFormat,
[]string{"section/sect1.rss.xml", "_default/rss.xml", "rss.xml", "_internal/_default/rss.xml"}}, []string{"section/sect1.rss.xml", "_default/rss.xml", "rss.xml", "_internal/_default/rss.xml"}},
{"RSS Taxonomy", LayoutDescriptor{Kind: "taxonomy", Section: "tag"}, false, "", RSSType, {"RSS Taxonomy", LayoutDescriptor{Kind: "taxonomy", Section: "tag"}, false, "", RSSFormat,
[]string{"taxonomy/tag.rss.xml", "_default/rss.xml", "rss.xml", "_internal/_default/rss.xml"}}, []string{"taxonomy/tag.rss.xml", "_default/rss.xml", "rss.xml", "_internal/_default/rss.xml"}},
{"RSS Taxonomy term", LayoutDescriptor{Kind: "taxonomyTerm", Section: "tag"}, false, "", RSSType, {"RSS Taxonomy term", LayoutDescriptor{Kind: "taxonomyTerm", Section: "tag"}, false, "", RSSFormat,
[]string{"taxonomy/tag.terms.rss.xml", "_default/rss.xml", "rss.xml", "_internal/_default/rss.xml"}}, []string{"taxonomy/tag.terms.rss.xml", "_default/rss.xml", "rss.xml", "_internal/_default/rss.xml"}},
} { } {
t.Run(this.name, func(t *testing.T) { t.Run(this.name, func(t *testing.T) {
@ -90,7 +90,7 @@ func BenchmarkLayout(b *testing.B) {
l := NewLayoutHandler(false) l := NewLayoutHandler(false)
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
layouts := l.For(descriptor, "", HTMLType) layouts := l.For(descriptor, "", HTMLFormat)
require.NotEmpty(b, layouts) require.NotEmpty(b, layouts)
} }
} }

View file

@ -22,9 +22,9 @@ import (
var ( var (
// An ordered list of built-in output formats // An ordered list of built-in output formats
//
// See https://www.ampproject.org/learn/overview/ // See https://www.ampproject.org/learn/overview/
// TODO(bep) output rename to AMPFormat etc. AMPFormat = Format{
AMPType = Format{
Name: "AMP", Name: "AMP",
MediaType: media.HTMLType, MediaType: media.HTMLType,
BaseName: "index", BaseName: "index",
@ -33,7 +33,7 @@ var (
IsHTML: true, IsHTML: true,
} }
CalendarType = Format{ CalendarFormat = Format{
Name: "Calendar", Name: "Calendar",
MediaType: media.CalendarType, MediaType: media.CalendarType,
IsPlainText: true, IsPlainText: true,
@ -42,14 +42,14 @@ var (
Rel: "alternate", Rel: "alternate",
} }
CSSType = Format{ CSSFormat = Format{
Name: "CSS", Name: "CSS",
MediaType: media.CSSType, MediaType: media.CSSType,
BaseName: "styles", BaseName: "styles",
Rel: "stylesheet", Rel: "stylesheet",
} }
HTMLType = Format{ HTMLFormat = Format{
Name: "HTML", Name: "HTML",
MediaType: media.HTMLType, MediaType: media.HTMLType,
BaseName: "index", BaseName: "index",
@ -57,7 +57,7 @@ var (
IsHTML: true, IsHTML: true,
} }
JSONType = Format{ JSONFormat = Format{
Name: "JSON", Name: "JSON",
MediaType: media.JSONType, MediaType: media.JSONType,
BaseName: "index", BaseName: "index",
@ -65,7 +65,7 @@ var (
Rel: "alternate", Rel: "alternate",
} }
RSSType = Format{ RSSFormat = Format{
Name: "RSS", Name: "RSS",
MediaType: media.RSSType, MediaType: media.RSSType,
BaseName: "index", BaseName: "index",
@ -75,12 +75,12 @@ var (
) )
var builtInTypes = map[string]Format{ var builtInTypes = map[string]Format{
strings.ToLower(AMPType.Name): AMPType, strings.ToLower(AMPFormat.Name): AMPFormat,
strings.ToLower(CalendarType.Name): CalendarType, strings.ToLower(CalendarFormat.Name): CalendarFormat,
strings.ToLower(CSSType.Name): CSSType, strings.ToLower(CSSFormat.Name): CSSFormat,
strings.ToLower(HTMLType.Name): HTMLType, strings.ToLower(HTMLFormat.Name): HTMLFormat,
strings.ToLower(JSONType.Name): JSONType, strings.ToLower(JSONFormat.Name): JSONFormat,
strings.ToLower(RSSType.Name): RSSType, strings.ToLower(RSSFormat.Name): RSSFormat,
} }
type Formats []Format type Formats []Format

View file

@ -21,41 +21,41 @@ import (
) )
func TestDefaultTypes(t *testing.T) { func TestDefaultTypes(t *testing.T) {
require.Equal(t, "Calendar", CalendarType.Name) require.Equal(t, "Calendar", CalendarFormat.Name)
require.Equal(t, media.CalendarType, CalendarType.MediaType) require.Equal(t, media.CalendarType, CalendarFormat.MediaType)
require.Equal(t, "webcal://", CalendarType.Protocol) require.Equal(t, "webcal://", CalendarFormat.Protocol)
require.Empty(t, CalendarType.Path) require.Empty(t, CalendarFormat.Path)
require.True(t, CalendarType.IsPlainText) require.True(t, CalendarFormat.IsPlainText)
require.False(t, CalendarType.IsHTML) require.False(t, CalendarFormat.IsHTML)
require.Equal(t, "HTML", HTMLType.Name) require.Equal(t, "HTML", HTMLFormat.Name)
require.Equal(t, media.HTMLType, HTMLType.MediaType) require.Equal(t, media.HTMLType, HTMLFormat.MediaType)
require.Empty(t, HTMLType.Path) require.Empty(t, HTMLFormat.Path)
require.Empty(t, HTMLType.Protocol) // Will inherit the BaseURL protocol. require.Empty(t, HTMLFormat.Protocol) // Will inherit the BaseURL protocol.
require.False(t, HTMLType.IsPlainText) require.False(t, HTMLFormat.IsPlainText)
require.True(t, HTMLType.IsHTML) require.True(t, HTMLFormat.IsHTML)
require.Equal(t, "AMP", AMPType.Name) require.Equal(t, "AMP", AMPFormat.Name)
require.Equal(t, media.HTMLType, AMPType.MediaType) require.Equal(t, media.HTMLType, AMPFormat.MediaType)
require.Equal(t, "amp", AMPType.Path) require.Equal(t, "amp", AMPFormat.Path)
require.Empty(t, AMPType.Protocol) // Will inherit the BaseURL protocol. require.Empty(t, AMPFormat.Protocol) // Will inherit the BaseURL protocol.
require.False(t, AMPType.IsPlainText) require.False(t, AMPFormat.IsPlainText)
require.True(t, AMPType.IsHTML) require.True(t, AMPFormat.IsHTML)
require.Equal(t, "RSS", RSSType.Name) require.Equal(t, "RSS", RSSFormat.Name)
require.Equal(t, media.RSSType, RSSType.MediaType) require.Equal(t, media.RSSType, RSSFormat.MediaType)
require.Empty(t, RSSType.Path) require.Empty(t, RSSFormat.Path)
require.False(t, RSSType.IsPlainText) require.False(t, RSSFormat.IsPlainText)
require.True(t, RSSType.NoUgly) require.True(t, RSSFormat.NoUgly)
require.False(t, CalendarType.IsHTML) require.False(t, CalendarFormat.IsHTML)
} }
func TestGetType(t *testing.T) { func TestGetType(t *testing.T) {
tp, _ := GetFormat("html") tp, _ := GetFormat("html")
require.Equal(t, HTMLType, tp) require.Equal(t, HTMLFormat, tp)
tp, _ = GetFormat("HTML") tp, _ = GetFormat("HTML")
require.Equal(t, HTMLType, tp) require.Equal(t, HTMLFormat, tp)
_, found := GetFormat("FOO") _, found := GetFormat("FOO")
require.False(t, found) require.False(t, found)
} }