summaryrefslogtreecommitdiffstats
path: root/output
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-03-16 08:32:14 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-03-27 15:43:56 +0200
commit4c2abe0015393de6e7a2af119c2df5b05879fe19 (patch)
treeac7d788472ff18e4e57a160e3eefb28e095bf60f /output
parent6bf010fed432e5574e19fd2946ee6397d895950e (diff)
Rename OutputType to OutputFormat
Diffstat (limited to 'output')
-rw-r--r--output/layout.go24
-rw-r--r--output/layout_test.go4
-rw-r--r--output/outputFormat.go (renamed from output/outputType.go)30
-rw-r--r--output/outputFormat_test.go (renamed from output/outputType_test.go)0
4 files changed, 29 insertions, 29 deletions
diff --git a/output/layout.go b/output/layout.go
index 1d2cbeed0..d9f1c7a4b 100644
--- a/output/layout.go
+++ b/output/layout.go
@@ -60,7 +60,7 @@ indexes/indexes.NAME.SUFFIX indexes/indexes.SUFFIX
`
)
-func (l *LayoutHandler) For(id LayoutIdentifier, layoutOverride string, tp Type) []string {
+func (l *LayoutHandler) For(id LayoutIdentifier, layoutOverride string, f Format) []string {
var layouts []string
layout := id.PageLayout()
@@ -72,15 +72,15 @@ func (l *LayoutHandler) For(id LayoutIdentifier, layoutOverride string, tp Type)
switch id.PageKind() {
// TODO(bep) move the Kind constants some common place.
case "home":
- layouts = resolveTemplate(layoutsHome, id, tp)
+ layouts = resolveTemplate(layoutsHome, id, f)
case "section":
- layouts = resolveTemplate(layoutsSection, id, tp)
+ layouts = resolveTemplate(layoutsSection, id, f)
case "taxonomy":
- layouts = resolveTemplate(layoutTaxonomy, id, tp)
+ layouts = resolveTemplate(layoutTaxonomy, id, f)
case "taxonomyTerm":
- layouts = resolveTemplate(layoutTaxonomyTerm, id, tp)
+ layouts = resolveTemplate(layoutTaxonomyTerm, id, f)
case "page":
- layouts = regularPageLayouts(id.PageType(), layout, tp)
+ layouts = regularPageLayouts(id.PageType(), layout, f)
}
if l.hasTheme {
@@ -112,10 +112,10 @@ func (l *LayoutHandler) For(id LayoutIdentifier, layoutOverride string, tp Type)
return layouts
}
-func resolveTemplate(templ string, id LayoutIdentifier, tp Type) []string {
+func resolveTemplate(templ string, id LayoutIdentifier, f Format) []string {
return strings.Fields(replaceKeyValues(templ,
- "SUFFIX", tp.MediaType.Suffix,
- "NAME", strings.ToLower(tp.Name),
+ "SUFFIX", f.MediaType.Suffix,
+ "NAME", strings.ToLower(f.Name),
"SECTION", id.PageSection()))
}
@@ -124,13 +124,13 @@ func replaceKeyValues(s string, oldNew ...string) string {
return replacer.Replace(s)
}
-func regularPageLayouts(types string, layout string, tp Type) (layouts []string) {
+func regularPageLayouts(types string, layout string, f Format) (layouts []string) {
if layout == "" {
layout = "single"
}
- suffix := tp.MediaType.Suffix
- name := strings.ToLower(tp.Name)
+ suffix := f.MediaType.Suffix
+ name := strings.ToLower(f.Name)
if types != "" {
t := strings.Split(types, "/")
diff --git a/output/layout_test.go b/output/layout_test.go
index 8f851b895..8b71bbe3b 100644
--- a/output/layout_test.go
+++ b/output/layout_test.go
@@ -44,7 +44,7 @@ func (l testLayoutIdentifier) PageSection() string {
return l.pageSection
}
-var ampType = Type{
+var ampType = Format{
Name: "AMP",
MediaType: media.HTMLType,
BaseName: "index",
@@ -57,7 +57,7 @@ func TestLayout(t *testing.T) {
li testLayoutIdentifier
hasTheme bool
layoutOverride string
- tp Type
+ tp Format
expect []string
}{
{"Home", testLayoutIdentifier{"home", "", "", ""}, true, "", ampType,
diff --git a/output/outputType.go b/output/outputFormat.go
index ad66b4b68..8c99aa139 100644
--- a/output/outputType.go
+++ b/output/outputFormat.go
@@ -23,33 +23,33 @@ import (
var (
// An ordered list of built-in output formats
// See https://www.ampproject.org/learn/overview/
- AMPType = Type{
+ AMPType = Format{
Name: "AMP",
MediaType: media.HTMLType,
BaseName: "index",
Path: "amp",
}
- CSSType = Type{
+ CSSType = Format{
Name: "CSS",
MediaType: media.CSSType,
BaseName: "styles",
}
- HTMLType = Type{
+ HTMLType = Format{
Name: "HTML",
MediaType: media.HTMLType,
BaseName: "index",
}
- JSONType = Type{
+ JSONType = Format{
Name: "JSON",
MediaType: media.JSONType,
BaseName: "index",
IsPlainText: true,
}
- RSSType = Type{
+ RSSType = Format{
Name: "RSS",
MediaType: media.RSSType,
BaseName: "index",
@@ -57,7 +57,7 @@ var (
}
)
-var builtInTypes = map[string]Type{
+var builtInTypes = map[string]Format{
strings.ToLower(AMPType.Name): AMPType,
strings.ToLower(CSSType.Name): CSSType,
strings.ToLower(HTMLType.Name): HTMLType,
@@ -65,11 +65,11 @@ var builtInTypes = map[string]Type{
strings.ToLower(RSSType.Name): RSSType,
}
-type Types []Type
+type Formats []Format
-// Type represents an output represenation, usually to a file on disk.
-type Type struct {
- // The Name is used as an identifier. Internal output types (i.e. HTML and RSS)
+// Format represents an output represenation, usually to a file on disk.
+type Format struct {
+ // The Name is used as an identifier. Internal output formats (i.e. HTML and RSS)
// can be overridden by providing a new definition for those types.
Name string
@@ -92,7 +92,7 @@ type Type struct {
NoUgly bool
}
-func GetType(key string) (Type, bool) {
+func GetType(key string) (Format, bool) {
found, ok := builtInTypes[key]
if !ok {
found, ok = builtInTypes[strings.ToLower(key)]
@@ -101,13 +101,13 @@ func GetType(key string) (Type, bool) {
}
// TODO(bep) outputs rewamp on global config?
-func GetTypes(keys ...string) (Types, error) {
- var types []Type
+func GetTypes(keys ...string) (Formats, error) {
+ var types []Format
for _, key := range keys {
tpe, ok := GetType(key)
if !ok {
- return types, fmt.Errorf("OutputType with key %q not found", key)
+ return types, fmt.Errorf("OutputFormat with key %q not found", key)
}
types = append(types, tpe)
}
@@ -115,6 +115,6 @@ func GetTypes(keys ...string) (Types, error) {
return types, nil
}
-func (t Type) BaseFilename() string {
+func (t Format) BaseFilename() string {
return t.BaseName + "." + t.MediaType.Suffix
}
diff --git a/output/outputType_test.go b/output/outputFormat_test.go
index 3eb56d8d3..3eb56d8d3 100644
--- a/output/outputType_test.go
+++ b/output/outputFormat_test.go