shithub: hugo

Download patch

ref: 5bda0398e7f865d993118f8826c895fdcdc7bb24
parent: e1729935b5a0159b22f90bd441698889e16d5ca5
author: Bjørn Erik Pedersen <[email protected]>
date: Mon Nov 2 12:24:50 EST 2015

Export Page.Layout

And at the same time rename and unexport the badly named `Layout()` func. That method is not very usable outside the package.

Fixes #1539

--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -65,7 +65,7 @@
 	extension           string
 	contentType         string
 	renderable          bool
-	layout              string
+	Layout              string
 	linkTitle           string
 	frontmatter         []byte
 	rawContent          []byte
@@ -302,9 +302,9 @@
 	return p.Source.Section()
 }
 
-func (p *Page) Layout(l ...string) []string {
-	if p.layout != "" {
-		return layouts(p.Type(), p.layout)
+func (p *Page) layouts(l ...string) []string {
+	if p.Layout != "" {
+		return layouts(p.Type(), p.Layout)
 	}
 
 	layout := ""
@@ -541,7 +541,7 @@
 			published = new(bool)
 			*published = cast.ToBool(v)
 		case "layout":
-			p.layout = cast.ToString(v)
+			p.Layout = cast.ToString(v)
 		case "markup":
 			p.Markup = cast.ToString(v)
 		case "weight":
@@ -764,7 +764,7 @@
 	if len(layout) > 0 {
 		l = layouts(p.Type(), layout[0])
 	} else {
-		l = p.Layout()
+		l = p.layouts()
 	}
 
 	return tpl.ExecuteTemplateToHTML(p, l...)
--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -502,8 +502,8 @@
 }
 
 func checkPageLayout(t *testing.T, page *Page, layout ...string) {
-	if !listEqual(page.Layout(), layout) {
-		t.Fatalf("Page layout is: %s.  Expected: %s", page.Layout(), layout)
+	if !listEqual(page.layouts(), layout) {
+		t.Fatalf("Page layout is: %s.  Expected: %s", page.layouts(), layout)
 	}
 }
 
@@ -909,8 +909,8 @@
 		for _, y := range test.expectedLayout {
 			test.expectedLayout = append(test.expectedLayout, "theme/"+y)
 		}
-		if !listEqual(p.Layout(), test.expectedLayout) {
-			t.Errorf("Layout mismatch. Expected: %s, got: %s", test.expectedLayout, p.Layout())
+		if !listEqual(p.layouts(), test.expectedLayout) {
+			t.Errorf("Layout mismatch. Expected: %s, got: %s", test.expectedLayout, p.layouts())
 		}
 	}
 }
--- a/hugolib/path_separators_test.go
+++ b/hugolib/path_separators_test.go
@@ -47,8 +47,8 @@
 			el.layout = append(el.layout, "theme/"+y)
 		}
 
-		if !listEqual(p.Layout(), el.layout) {
-			t.Errorf("[%d] Layout incorrect. got '%s' but expected '%s'", i, p.Layout(), el.layout)
+		if !listEqual(p.layouts(), el.layout) {
+			t.Errorf("[%d] Layout incorrect. got '%s' but expected '%s'", i, p.layouts(), el.layout)
 		}
 	}
 }
--- a/hugolib/planner.go
+++ b/hugolib/planner.go
@@ -18,7 +18,7 @@
 			fmt.Fprintf(out, " (renderer: n/a)")
 		}
 		if s.Tmpl != nil {
-			for _, l := range p.Layout() {
+			for _, l := range p.layouts() {
 				fmt.Fprintf(out, " (layout: %s, exists: %t)", l, s.Tmpl.Lookup(l) != nil)
 			}
 		}
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -943,7 +943,7 @@
 			}
 			layouts = append(layouts, self)
 		} else {
-			layouts = append(layouts, p.Layout()...)
+			layouts = append(layouts, p.layouts()...)
 			layouts = append(layouts, "_default/single.html")
 		}