Skip to content

Commit

Permalink
Fix GetPage Params case issue
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Nov 21, 2019
1 parent 86a7aee commit c6ea092
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
5 changes: 5 additions & 0 deletions hugolib/case_insensitive_test.go
Expand Up @@ -179,6 +179,10 @@ Site Title: {{ .Site.Title }}
Site Lang Mood: {{ .Site.Language.Params.MOoD }}
Page Colors: {{ .Params.COLOR }}|{{ .Params.Colors.Blue }}
Site Colors: {{ .Site.Params.COLOR }}|{{ .Site.Params.COLORS.YELLOW }}
{{ $page2 := .Site.GetPage "/sect2/page2" }}
{{ if $page2 }}
Page2: {{ $page2.Params.ColoR }}
{{ end }}
{{ .Content }}
{{ partial "partial.html" . }}
`)
Expand Down Expand Up @@ -207,6 +211,7 @@ Site Colors: {{ .Site.Params.COLOR }}|{{ .Site.Params.COLORS.YELLOW }}
"Page Title: Side 1",
"Site Title: Nynorsk title",
"«Hi»", // angled quotes
"Page2: black ",
)

th.assertFileContent(filepath.Join("public", "en", "sect1", "page1", "index.html"),
Expand Down
2 changes: 1 addition & 1 deletion hugolib/testhelpers_test.go
Expand Up @@ -743,7 +743,7 @@ func (th testHelper) assertFileContent(filename string, matches ...string) {
content := readDestination(th, th.Fs, filename)
for _, match := range matches {
match = th.replaceDefaultContentLanguageValue(match)
th.Assert(strings.Contains(content, match), qt.Equals, true)
th.Assert(strings.Contains(content, match), qt.Equals, true, qt.Commentf(content))
}
}

Expand Down
3 changes: 1 addition & 2 deletions tpl/tplimpl/template_ast_transformers.go
Expand Up @@ -508,8 +508,7 @@ func (d decl) resolveVariables(idents []string) ([]string, bool) {
}

if !d.isKeyword(replacement) {
// This can not be .Site.Params etc.
return nil, false
continue
}

replacement = strings.TrimPrefix(replacement, ".")
Expand Down
14 changes: 7 additions & 7 deletions tpl/tplimpl/template_ast_transformers_test.go
Expand Up @@ -35,7 +35,7 @@ func (p paramsHolder) Params() map[string]interface{} {
return p.params
}

func (p paramsHolder) GetPage() *paramsHolder {
func (p paramsHolder) GetPage(arg string) *paramsHolder {
return p.page
}

Expand Down Expand Up @@ -200,10 +200,10 @@ PARAMS SITE GLOBAL1: {{ site.Params.LOwER }}
PARAMS SITE GLOBAL2: {{ $lower }}
PARAMS SITE GLOBAL3: {{ $site.Params.LOWER }}
{{ $p := $site.GetPage }}
PARAMS GETPAGE {{ $p.Params.LOWER }}
{{ $p := .Site2.GetPage }}
PARAMS GETPAGE2 {{ $p.Params.LOWER }}
{{ $p := $site.GetPage "foo" }}
PARAMS GETPAGE: {{ $p.Params.LOWER }}
{{ $p := .Site2.GetPage "foo" }}
PARAMS GETPAGE2: {{ $p.Params.LOWER }}
`
)

Expand Down Expand Up @@ -283,8 +283,8 @@ func TestParamsKeysToLower(t *testing.T) {
c.Assert(result, qt.Contains, "PARAMS SITE GLOBAL3: global-site")

//
c.Assert(result, qt.Contains, "PARAMS GETPAGE page")
c.Assert(result, qt.Contains, "PARAMS GETPAGE2 page")
c.Assert(result, qt.Contains, "PARAMS GETPAGE: page")
c.Assert(result, qt.Contains, "PARAMS GETPAGE2: page")

}

Expand Down

0 comments on commit c6ea092

Please sign in to comment.