...
1 package exec
2
3 import (
4 "strings"
5
6 "github.com/noirbizarre/gonja/nodes"
7 )
8
9 func getBlocks(tpl *nodes.Template) map[string]*nodes.Wrapper {
10 if tpl == nil {
11 return map[string]*nodes.Wrapper{}
12 }
13 blocks := getBlocks(tpl.Parent)
14 for name, wrapper := range tpl.Blocks {
15 blocks[name] = wrapper
16 }
17 return blocks
18 }
19
20 func Self(r *Renderer) map[string]func() string {
21 blocks := map[string]func() string{}
22 for name, block := range getBlocks(r.Root) {
23 blocks[name] = func() string {
24 sub := r.Inherit()
25 var out strings.Builder
26 sub.Out = &out
27 sub.ExecuteWrapper(block)
28 return out.String()
29 }
30 }
31 return blocks
32 }
33
View as plain text