summaryrefslogtreecommitdiffstats
path: root/output
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-03-06 13:18:33 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-03-27 15:43:56 +0200
commit10de077164501e18a253e7abb77af8824cfebb8a (patch)
treea5c99f20362b9b358b4ecc3168820f022724b9b6 /output
parent3bb52bf7bff72457481acabfe8268915e23a7d23 (diff)
hugolib: Use the new layout logic in Page
Diffstat (limited to 'output')
-rw-r--r--output/layout.go13
-rw-r--r--output/layout_test.go28
2 files changed, 25 insertions, 16 deletions
diff --git a/output/layout.go b/output/layout.go
index 7646caf48..ba246237a 100644
--- a/output/layout.go
+++ b/output/layout.go
@@ -19,6 +19,7 @@ import (
"strings"
)
+// LayoutIdentifier is used to pick the correct layout for a piece of content.
type LayoutIdentifier interface {
PageType() string
PageSection() string // TODO(bep) name
@@ -28,7 +29,7 @@ type LayoutIdentifier interface {
// Layout calculates the layout template to use to render a given output type.
// TODO(bep) output improve names
-type Layout struct {
+type LayoutHandler struct {
}
// TODO(bep) output theme layouts
@@ -39,9 +40,15 @@ var (
layoutTaxonomyTerm = "taxonomy/SECTION.terms.html _default/terms.html indexes/indexes.html"
)
-func (l *Layout) For(id LayoutIdentifier, tp Type) []string {
+func (l *LayoutHandler) For(id LayoutIdentifier, layoutOverride string, tp Type) []string {
var layouts []string
+ layout := id.PageLayout()
+
+ if layoutOverride != "" {
+ layout = layoutOverride
+ }
+
switch id.PageKind() {
// TODO(bep) move the Kind constants some common place.
case "home":
@@ -53,7 +60,7 @@ func (l *Layout) For(id LayoutIdentifier, tp Type) []string {
case "taxonomyTerm":
layouts = strings.Fields(strings.Replace(layoutTaxonomyTerm, "SECTION", id.PageSection(), -1))
case "page":
- layouts = regularPageLayouts(id.PageType(), id.PageLayout())
+ layouts = regularPageLayouts(id.PageType(), layout)
}
for _, l := range layouts {
diff --git a/output/layout_test.go b/output/layout_test.go
index 897b451c9..5b95e01d8 100644
--- a/output/layout_test.go
+++ b/output/layout_test.go
@@ -43,23 +43,25 @@ func (l testLayoutIdentifier) PageSection() string {
}
func TestLayout(t *testing.T) {
- l := &Layout{}
+ l := &LayoutHandler{}
for _, this := range []struct {
- li testLayoutIdentifier
- tp Type
- expect []string
+ li testLayoutIdentifier
+ layoutOverride string
+ tp Type
+ expect []string
}{
- {testLayoutIdentifier{"home", "", "", ""}, HTMLType, []string{"index.html", "_default/list.html", "theme/index.html", "theme/_default/list.html"}},
- {testLayoutIdentifier{"section", "sect1", "", ""}, HTMLType, []string{"section/sect1.html", "sect1/list.html"}},
- {testLayoutIdentifier{"taxonomy", "tag", "", ""}, HTMLType, []string{"taxonomy/tag.html", "indexes/tag.html"}},
- {testLayoutIdentifier{"taxonomyTerm", "categories", "", ""}, HTMLType, []string{"taxonomy/categories.terms.html", "_default/terms.html"}},
- {testLayoutIdentifier{"page", "", "", ""}, HTMLType, []string{"_default/single.html", "theme/_default/single.html"}},
- {testLayoutIdentifier{"page", "", "mylayout", ""}, HTMLType, []string{"_default/mylayout.html"}},
- {testLayoutIdentifier{"page", "", "mylayout", "myttype"}, HTMLType, []string{"myttype/mylayout.html", "_default/mylayout.html"}},
- {testLayoutIdentifier{"page", "", "mylayout", "myttype/mysubtype"}, HTMLType, []string{"myttype/mysubtype/mylayout.html", "myttype/mylayout.html", "_default/mylayout.html"}},
+ {testLayoutIdentifier{"home", "", "", ""}, "", HTMLType, []string{"index.html", "_default/list.html", "theme/index.html", "theme/_default/list.html"}},
+ {testLayoutIdentifier{"section", "sect1", "", ""}, "", HTMLType, []string{"section/sect1.html", "sect1/list.html"}},
+ {testLayoutIdentifier{"taxonomy", "tag", "", ""}, "", HTMLType, []string{"taxonomy/tag.html", "indexes/tag.html"}},
+ {testLayoutIdentifier{"taxonomyTerm", "categories", "", ""}, "", HTMLType, []string{"taxonomy/categories.terms.html", "_default/terms.html"}},
+ {testLayoutIdentifier{"page", "", "", ""}, "", HTMLType, []string{"_default/single.html", "theme/_default/single.html"}},
+ {testLayoutIdentifier{"page", "", "mylayout", ""}, "", HTMLType, []string{"_default/mylayout.html"}},
+ {testLayoutIdentifier{"page", "", "mylayout", "myttype"}, "", HTMLType, []string{"myttype/mylayout.html", "_default/mylayout.html"}},
+ {testLayoutIdentifier{"page", "", "mylayout", "myttype/mysubtype"}, "", HTMLType, []string{"myttype/mysubtype/mylayout.html", "myttype/mylayout.html", "_default/mylayout.html"}},
+ {testLayoutIdentifier{"page", "", "mylayout", "myttype"}, "myotherlayout", HTMLType, []string{"myttype/myotherlayout.html", "_default/myotherlayout.html"}},
} {
- layouts := l.For(this.li, this.tp)
+ layouts := l.For(this.li, this.layoutOverride, this.tp)
require.NotNil(t, layouts)
require.True(t, len(layouts) >= len(this.expect))
// Not checking the complete list for now ...