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
This commit is contained in:
Bjørn Erik Pedersen 2015-11-02 17:24:50 +01:00
parent e1729935b5
commit 5bda0398e7
5 changed files with 14 additions and 14 deletions

View file

@ -65,7 +65,7 @@ type Page struct {
extension string extension string
contentType string contentType string
renderable bool renderable bool
layout string Layout string
linkTitle string linkTitle string
frontmatter []byte frontmatter []byte
rawContent []byte rawContent []byte
@ -302,9 +302,9 @@ func (p *Page) Section() string {
return p.Source.Section() return p.Source.Section()
} }
func (p *Page) Layout(l ...string) []string { func (p *Page) layouts(l ...string) []string {
if p.layout != "" { if p.Layout != "" {
return layouts(p.Type(), p.layout) return layouts(p.Type(), p.Layout)
} }
layout := "" layout := ""
@ -541,7 +541,7 @@ func (p *Page) update(f interface{}) error {
published = new(bool) published = new(bool)
*published = cast.ToBool(v) *published = cast.ToBool(v)
case "layout": case "layout":
p.layout = cast.ToString(v) p.Layout = cast.ToString(v)
case "markup": case "markup":
p.Markup = cast.ToString(v) p.Markup = cast.ToString(v)
case "weight": case "weight":
@ -764,7 +764,7 @@ func (p *Page) Render(layout ...string) template.HTML {
if len(layout) > 0 { if len(layout) > 0 {
l = layouts(p.Type(), layout[0]) l = layouts(p.Type(), layout[0])
} else { } else {
l = p.Layout() l = p.layouts()
} }
return tpl.ExecuteTemplateToHTML(p, l...) return tpl.ExecuteTemplateToHTML(p, l...)

View file

@ -502,8 +502,8 @@ func checkPageType(t *testing.T, page *Page, pageType string) {
} }
func checkPageLayout(t *testing.T, page *Page, layout ...string) { func checkPageLayout(t *testing.T, page *Page, layout ...string) {
if !listEqual(page.Layout(), layout) { if !listEqual(page.layouts(), layout) {
t.Fatalf("Page layout is: %s. Expected: %s", page.Layout(), 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 { for _, y := range test.expectedLayout {
test.expectedLayout = append(test.expectedLayout, "theme/"+y) test.expectedLayout = append(test.expectedLayout, "theme/"+y)
} }
if !listEqual(p.Layout(), test.expectedLayout) { if !listEqual(p.layouts(), test.expectedLayout) {
t.Errorf("Layout mismatch. Expected: %s, got: %s", test.expectedLayout, p.Layout()) t.Errorf("Layout mismatch. Expected: %s, got: %s", test.expectedLayout, p.layouts())
} }
} }
} }

View file

@ -47,8 +47,8 @@ func TestNewPageWithFilePath(t *testing.T) {
el.layout = append(el.layout, "theme/"+y) el.layout = append(el.layout, "theme/"+y)
} }
if !listEqual(p.Layout(), el.layout) { if !listEqual(p.layouts(), el.layout) {
t.Errorf("[%d] Layout incorrect. got '%s' but expected '%s'", i, p.Layout(), el.layout) t.Errorf("[%d] Layout incorrect. got '%s' but expected '%s'", i, p.layouts(), el.layout)
} }
} }
} }

View file

@ -18,7 +18,7 @@ func (s *Site) ShowPlan(out io.Writer) (err error) {
fmt.Fprintf(out, " (renderer: n/a)") fmt.Fprintf(out, " (renderer: n/a)")
} }
if s.Tmpl != nil { 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) fmt.Fprintf(out, " (layout: %s, exists: %t)", l, s.Tmpl.Lookup(l) != nil)
} }
} }

View file

@ -943,7 +943,7 @@ func pageRenderer(s *Site, pages <-chan *Page, results chan<- error, wg *sync.Wa
} }
layouts = append(layouts, self) layouts = append(layouts, self)
} else { } else {
layouts = append(layouts, p.Layout()...) layouts = append(layouts, p.layouts()...)
layouts = append(layouts, "_default/single.html") layouts = append(layouts, "_default/single.html")
} }