summaryrefslogtreecommitdiffstats
path: root/output
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-03-06 19:54:46 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-03-27 15:43:56 +0200
commit50c64415aa6593ba93bff086602a121aa9760d40 (patch)
tree56f55d399a09db8d5d83271080a238b834e7afb9 /output
parent348834d0176611fc0a08121b86c40e37644a89e3 (diff)
hugolib, output: Add theme logic to LayoutHandler
Diffstat (limited to 'output')
-rw-r--r--output/layout.go31
-rw-r--r--output/layout_test.go46
2 files changed, 61 insertions, 16 deletions
diff --git a/output/layout.go b/output/layout.go
index ba246237a..0e0f33dad 100644
--- a/output/layout.go
+++ b/output/layout.go
@@ -30,6 +30,11 @@ type LayoutIdentifier interface {
// Layout calculates the layout template to use to render a given output type.
// TODO(bep) output improve names
type LayoutHandler struct {
+ hasTheme bool
+}
+
+func NewLayoutHandler(hasTheme bool) *LayoutHandler {
+ return &LayoutHandler{hasTheme: hasTheme}
}
// TODO(bep) output theme layouts
@@ -63,8 +68,30 @@ func (l *LayoutHandler) For(id LayoutIdentifier, layoutOverride string, tp Type)
layouts = regularPageLayouts(id.PageType(), layout)
}
- for _, l := range layouts {
- layouts = append(layouts, "theme/"+l)
+ if l.hasTheme {
+ layoutsWithThemeLayouts := []string{}
+ // First place all non internal templates
+ for _, t := range layouts {
+ if !strings.HasPrefix(t, "_internal/") {
+ layoutsWithThemeLayouts = append(layoutsWithThemeLayouts, t)
+ }
+ }
+
+ // Then place theme templates with the same names
+ for _, t := range layouts {
+ if !strings.HasPrefix(t, "_internal/") {
+ layoutsWithThemeLayouts = append(layoutsWithThemeLayouts, "theme/"+t)
+ }
+ }
+
+ // Lastly place internal templates
+ for _, t := range layouts {
+ if strings.HasPrefix(t, "_internal/") {
+ layoutsWithThemeLayouts = append(layoutsWithThemeLayouts, t)
+ }
+ }
+
+ return layoutsWithThemeLayouts
}
return layouts
diff --git a/output/layout_test.go b/output/layout_test.go
index 5b95e01d8..333216e17 100644
--- a/output/layout_test.go
+++ b/output/layout_test.go
@@ -14,6 +14,7 @@
package output
import (
+ "fmt"
"testing"
"github.com/stretchr/testify/require"
@@ -43,28 +44,45 @@ func (l testLayoutIdentifier) PageSection() string {
}
func TestLayout(t *testing.T) {
- l := &LayoutHandler{}
- for _, this := range []struct {
+ for i, this := range []struct {
li testLayoutIdentifier
+ hasTheme bool
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{"page", "", "mylayout", "myttype"}, "myotherlayout", HTMLType, []string{"myttype/myotherlayout.html", "_default/myotherlayout.html"}},
+ {testLayoutIdentifier{"home", "", "", ""}, true, "", HTMLType,
+ []string{"index.html", "_default/list.html", "theme/index.html", "theme/_default/list.html"}},
+ {testLayoutIdentifier{"section", "sect1", "", ""}, false, "", HTMLType,
+ []string{"section/sect1.html", "sect1/list.html"}},
+ {testLayoutIdentifier{"taxonomy", "tag", "", ""}, false, "", HTMLType,
+ []string{"taxonomy/tag.html", "indexes/tag.html"}},
+ {testLayoutIdentifier{"taxonomyTerm", "categories", "", ""}, false, "", HTMLType,
+ []string{"taxonomy/categories.terms.html", "_default/terms.html"}},
+ {testLayoutIdentifier{"page", "", "", ""}, true, "", HTMLType,
+ []string{"_default/single.html", "theme/_default/single.html"}},
+ {testLayoutIdentifier{"page", "", "mylayout", ""}, false, "", HTMLType,
+ []string{"_default/mylayout.html"}},
+ {testLayoutIdentifier{"page", "", "mylayout", "myttype"}, false, "", HTMLType,
+ []string{"myttype/mylayout.html", "_default/mylayout.html"}},
+ {testLayoutIdentifier{"page", "", "mylayout", "myttype/mysubtype"}, false, "", HTMLType,
+ []string{"myttype/mysubtype/mylayout.html", "myttype/mylayout.html", "_default/mylayout.html"}},
+ {testLayoutIdentifier{"page", "", "mylayout", "myttype"}, false, "myotherlayout", HTMLType,
+ []string{"myttype/myotherlayout.html", "_default/myotherlayout.html"}},
} {
+ l := NewLayoutHandler(this.hasTheme)
+ logMsg := fmt.Sprintf("Test %d", i)
layouts := l.For(this.li, this.layoutOverride, this.tp)
- require.NotNil(t, layouts)
- require.True(t, len(layouts) >= len(this.expect))
+ require.NotNil(t, layouts, logMsg)
+ require.True(t, len(layouts) >= len(this.expect), logMsg)
// Not checking the complete list for now ...
- require.Equal(t, this.expect, layouts[:len(this.expect)])
+ require.Equal(t, this.expect, layouts[:len(this.expect)], logMsg)
+
+ if !this.hasTheme {
+ for _, layout := range layouts {
+ require.NotContains(t, layout, "theme", logMsg)
+ }
+ }
}
}