Skip to content

Commit

Permalink
resources/page: Re-introduce .Page.Page
Browse files Browse the repository at this point in the history
It was removed in 597e418 -- it's not documented, but it's used in too many real sites on the web.

See #5784
  • Loading branch information
bep committed Mar 25, 2019
1 parent b5f39d2 commit 91ef965
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions hugolib/page__tree.go
Expand Up @@ -104,6 +104,10 @@ func (pt pageTree) InSection(other interface{}) (bool, error) {

}

func (pt pageTree) Page() page.Page {
return pt.p
}

func (pt pageTree) Parent() page.Page {
return pt.p.parent
}
Expand Down
4 changes: 4 additions & 0 deletions resources/page/page.go
Expand Up @@ -340,6 +340,10 @@ type TreeProvider interface {
// Sections returns this section's subsections, if any.
// Note that for non-sections, this method will always return an empty list.
Sections() Pages

// Page returns a reference to the Page itself, kept here mostly
// for legacy reasons.
Page() Page
}

// DeprecatedWarningPageMethods lists deprecated Page methods that will trigger
Expand Down
7 changes: 6 additions & 1 deletion resources/page/page_generate/generate_page_wrappers.go
Expand Up @@ -107,7 +107,12 @@ func generateMarshalJSON(c *codegen.Inspector) error {
return errors.New("no methods found")
}

marshalJSON, pkgImports := methods.ToMarshalJSON("Page", "github.com/gohugoio/hugo/resources/page")
marshalJSON, pkgImports := methods.ToMarshalJSON(
"Page",
"github.com/gohugoio/hugo/resources/page",
// Exclusion regexps. Matches method names.
`\bPage\b`,
)

fmt.Fprintf(f, `%s
Expand Down
4 changes: 4 additions & 0 deletions resources/page/page_nop.go
Expand Up @@ -299,6 +299,10 @@ func (p *nopPage) Params() map[string]interface{} {
return nil
}

func (p *nopPage) Page() Page {
return p
}

func (p *nopPage) Parent() Page {
return nil
}
Expand Down
4 changes: 4 additions & 0 deletions resources/page/testhelpers_test.go
Expand Up @@ -360,6 +360,10 @@ func (p *testPage) Params() map[string]interface{} {
return p.params
}

func (p *testPage) Page() Page {
return p
}

func (p *testPage) Parent() Page {
panic("not implemented")
}
Expand Down

0 comments on commit 91ef965

Please sign in to comment.