I just needed the top object again.  Make helper.
Golang templates are mostly pretty smooth to get started with,
but this particular issue is really a bizarre tripwire, imo.
Will clean up the existing "range modifies dot unhelpfully" messes
sometime over the rainbow; I just refuse to make more of them today.
@@ -25,6 +25,11 @@ func doTemplate(tmplstr string, w io.Writer, adjCfg *AdjunctCfg, data interface{
// Access methods like UnionMemlayout through this, as e.g. `.AdjCfg.UnionMemlayout`.
"AdjCfg": func() *AdjunctCfg { return adjCfg },
+ // "dot" is a dummy value that's equal to the original `.` expression, but stays there.
+ // Use this if you're inside a range or other feature that shifted the dot and you want the original.
+ // (This may seem silly, but empirically, I found myself writing a dummy line to store the value of dot before endering a range clause >20 times; that's plenty.)
+ "dot": func() interface{} { return data },
+
"KindPrim": func(k ipld.ReprKind) string {
switch k {
case ipld.ReprKind_Map:
@@ -52,10 +57,6 @@ func doTemplate(tmplstr string, w io.Writer, adjCfg *AdjunctCfg, data interface{
"add": func(a, b int) int { return a + b },
"title": func(s string) string { return strings.Title(s) },
}).
- // Seriously consider prepending `{{ $dot := . }}` (or 'top', or something).
- // Or a func into the map that causes `dot` to mean `func() interface{} { return data }`.
- // The number of times that the range feature has a dummy capture line above it is... not reasonable.
- // (Grep for "/* ranging modifies dot, unhelpfully */" -- empirically, it's over 20 times already.)
Parse(wish.Dedent(tmplstr)))
if err := tmpl.Execute(w, data); err != nil {
panic(err)
