Export Page.Layout
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 2 Nov 2015 16:24:50 +0000 (17:24 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 2 Nov 2015 16:24:50 +0000 (17:24 +0100)
And at the same time rename and unexport the badly named `Layout()` func. That method is not very usable outside the package.

Fixes #1539

hugolib/page.go
hugolib/page_test.go
hugolib/path_separators_test.go
hugolib/planner.go
hugolib/site.go

index 2979822c3bd0add00db4226c983ffd194713bffe..a384c35e7d75d2b4f95b33375ea26710dc57f2f1 100644 (file)
@@ -65,7 +65,7 @@ type Page struct {
        extension           string
        contentType         string
        renderable          bool
-       layout              string
+       Layout              string
        linkTitle           string
        frontmatter         []byte
        rawContent          []byte
@@ -302,9 +302,9 @@ func (p *Page) Section() string {
        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 @@ func (p *Page) update(f interface{}) error {
                        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 @@ func (p *Page) Render(layout ...string) template.HTML {
        if len(layout) > 0 {
                l = layouts(p.Type(), layout[0])
        } else {
-               l = p.Layout()
+               l = p.layouts()
        }
 
        return tpl.ExecuteTemplateToHTML(p, l...)
index 9134ba6c6445ecc6207fc53c05ef099f51d4fb4a..df7daede493a42f9b0de1359e88f88eb16931f13 100644 (file)
@@ -502,8 +502,8 @@ func checkPageType(t *testing.T, page *Page, pageType string) {
 }
 
 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 @@ func TestLayoutOverride(t *testing.T) {
                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())
                }
        }
 }
index b45d5f331e9846db77a019e268e20a4a7e84382f..b3c7c2d9c9f5f1e3b8bb8b0e68e10b625e142012 100644 (file)
@@ -47,8 +47,8 @@ func TestNewPageWithFilePath(t *testing.T) {
                        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)
                }
        }
 }
index 7f03bbb0af07bfe02f42b9f2cae52960c3d10981..f2f19f3fa46c3bd64c7dd76f82d602495475f326 100644 (file)
@@ -18,7 +18,7 @@ func (s *Site) ShowPlan(out io.Writer) (err error) {
                        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)
                        }
                }
index 743cc082663b5e7da9c6c62220a739f0b7e2ae31..7fe9717a500c2ef6f0ec3dd92248e1907e1b262d 100644 (file)
@@ -943,7 +943,7 @@ func pageRenderer(s *Site, pages <-chan *Page, results chan<- error, wg *sync.Wa
                        }
                        layouts = append(layouts, self)
                } else {
-                       layouts = append(layouts, p.Layout()...)
+                       layouts = append(layouts, p.layouts()...)
                        layouts = append(layouts, "_default/single.html")
                }