Fix GetPage Params case issue

Fixes #5946
This commit is contained in:
Bjørn Erik Pedersen 2019-11-21 19:45:03 +01:00
parent 628efd6e29
commit cd07e6d57b
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F
4 changed files with 48 additions and 6 deletions

View file

@ -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" . }}
`)
@ -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"),

View file

@ -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))
}
}

View file

@ -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, ".")

View file

@ -26,6 +26,19 @@ import (
qt "github.com/frankban/quicktest"
)
type paramsHolder struct {
params map[string]interface{}
page *paramsHolder
}
func (p paramsHolder) Params() map[string]interface{} {
return p.params
}
func (p paramsHolder) GetPage(arg string) *paramsHolder {
return p.page
}
var (
testFuncs = map[string]interface{}{
"getif": func(v interface{}) interface{} { return v },
@ -37,16 +50,22 @@ var (
"ByWeight": fmt.Sprintf("%v:%v:%v", seq, key, args),
}, nil
},
"site": func() interface{} {
return map[string]interface{}{
"Params": map[string]interface{}{
"site": func() paramsHolder {
return paramsHolder{
params: map[string]interface{}{
"lower": "global-site",
},
page: &paramsHolder{
params: map[string]interface{}{
"lower": "page",
},
},
}
},
}
paramsData = map[string]interface{}{
"NotParam": "Hi There",
"Slice": []int{1, 3},
"Params": map[string]interface{}{
@ -81,6 +100,16 @@ var (
},
},
},
"Site2": paramsHolder{
params: map[string]interface{}{
"lower": "global-site",
},
page: &paramsHolder{
params: map[string]interface{}{
"lower": "page",
},
},
},
}
paramsTempl = `
@ -170,6 +199,11 @@ PARAMS SITE GLOBAL1: {{ site.Params.LOwER }}
{{ $site := site }}
PARAMS SITE GLOBAL2: {{ $lower }}
PARAMS SITE GLOBAL3: {{ $site.Params.LOWER }}
{{ $p := $site.GetPage "foo" }}
PARAMS GETPAGE: {{ $p.Params.LOWER }}
{{ $p := .Site2.GetPage "foo" }}
PARAMS GETPAGE2: {{ $p.Params.LOWER }}
`
)
@ -248,6 +282,10 @@ func TestParamsKeysToLower(t *testing.T) {
c.Assert(result, qt.Contains, "PARAMS SITE GLOBAL2: global-site")
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")
}
func BenchmarkTemplateParamsKeysToLower(b *testing.B) {