ref: fdff0d3af4670f7079e539fef4b92af2a866d02d
parent: 834617f9f8d870643b2631fe607471c8e2ef2f47
author: Bjørn Erik Pedersen <[email protected]>
date: Sun Aug 19 09:30:42 EDT 2018
tpl/tplimpl: Fix .Site.Params case regression Fixes #5094
--- a/tpl/tplimpl/template_ast_transformers.go
+++ b/tpl/tplimpl/template_ast_transformers.go
@@ -213,17 +213,7 @@
// .Data.Params.someKey
return -1
}
- if !d.isKeyword(container) {
- // where $pages ".Params.toc_hide" "!=" true
- return -1
- }
}
- if i < len(resolvedIdents)-1 {
- next := resolvedIdents[i+1]
- if !d.isKeyword(next) {
- return -1
- }
- }
paramFound = true
break
@@ -295,6 +285,11 @@
if !ok {
// Temporary range vars. We do not care about those.
+ return nil, false
+ }
+
+ if !d.isKeyword(replacement) {
+ // This can not be .Site.Params etc.
return nil, false
}
--- a/tpl/tplimpl/template_ast_transformers_test.go
+++ b/tpl/tplimpl/template_ast_transformers_test.go
@@ -24,7 +24,8 @@
var (
testFuncs = map[string]interface{}{
- "Echo": func(v interface{}) interface{} { return v },
+ "First": func(v ...interface{}) interface{} { return v[0] },
+ "Echo": func(v interface{}) interface{} { return v },
"where": func(seq, key interface{}, args ...interface{}) (interface{}, error) {
return map[string]interface{}{
"ByWeight": fmt.Sprintf("%v:%v:%v", seq, key, args),
@@ -55,6 +56,9 @@
"Language": map[string]interface{}{
"Params": map[string]interface{}{
"lower": "P22L",
+ "nested": map[string]interface{}{
+ "lower": "P22L_nested",
+ },
},
},
"Data": map[string]interface{}{
@@ -84,6 +88,7 @@
P2_3: {{ $site.Params.LOWER }}
P2_4: {{ $siteParams.LOWER }}
P22: {{ .Site.Language.Params.LOWER }}
+P22_nested: {{ .Site.Language.Params.NESTED.LOWER }}
P3: {{ .Site.Data.Params.NOLOW }}
P3_2: {{ $.Site.Data.Params.NOLOW }}
P3_3: {{ $site.Data.Params.NOLOW }}
@@ -135,6 +140,8 @@
PARAMS STRING2: {{ with $pages }}{{ .ByWeight }}{{ end }}
{{ $pages3 := where ".Params.TOC_HIDE" "!=" .Params.LOWER }}
PARAMS STRING3: {{ $pages3.ByWeight }}
+{{ $first := First .Pages .Site.Params.LOWER }}
+PARAMS COMPOSITE: {{ $first.ByWeight }}
`
)
@@ -168,6 +175,7 @@
require.Contains(t, result, "P2_3: P2L")
require.Contains(t, result, "P2_4: P2L")
require.Contains(t, result, "P22: P22L")
+ require.Contains(t, result, "P22_nested: P22L_nested")
require.Contains(t, result, "P3: P3H")
require.Contains(t, result, "P3_2: P3H")
require.Contains(t, result, "P3_3: P3H")
@@ -194,6 +202,9 @@
require.Contains(t, result, "PARAMS STRING: foo:.Params.toc_hide:[!= true]")
require.Contains(t, result, "PARAMS STRING2: foo:.Params.toc_hide:[!= true]")
require.Contains(t, result, "PARAMS STRING3: .Params.TOC_HIDE:!=:[P1L]")
+
+ // Issue #5094
+ require.Contains(t, result, "PARAMS COMPOSITE: [1 3]")
// Issue #5068
require.Contains(t, result, "PCurrentSection: pcurrentsection")