Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func parseLayout(root templateSet, t templateFile, funcMap template.FuncMap) (*t
}

// process template tree for layout
refs, err := processTree(layout, t.body, true, true)
refs, err := processTree(layout, t.body)
if err != nil {
return nil, fmt.Errorf("error processing layout: %w", err)
}
Expand Down Expand Up @@ -206,7 +206,7 @@ func parseView(root templateSet, layout *template.Template, name, raw string) (*
}

// process template tree for body
refs, err := processTree(body, raw, false, true)
refs, err := processTree(body, raw)
if err != nil {
return nil, fmt.Errorf("error parsing view '%s': %w", name, err)
}
Expand Down
26 changes: 10 additions & 16 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

// processTree traverses the node tree and swaps render and partial declarations with equivalent template calls.
// It returns all referenced templates encountered during the traversal.
func processTree(t *template.Template, raw string, render, partial bool) ([]templateName, error) {
ts, err := processNode(nil, 0, t.Tree.Root, render, partial)
func processTree(t *template.Template, raw string) ([]templateName, error) {
ts, err := processNode(nil, 0, t.Tree.Root)
if err != nil {
if err, ok := err.(posErr); ok {
line, col := pos(raw, err.pos)
Expand All @@ -21,13 +21,7 @@ func processTree(t *template.Template, raw string, render, partial bool) ([]temp
return ts, nil
}

func processNode(
parent *parse.ListNode,
index int,
node parse.Node,
render,
partial bool,
) (ts []templateName, err error) {
func processNode(parent *parse.ListNode, index int, node parse.Node) (ts []templateName, err error) {
// appendResult appends the specified templates to the list of template names when there are no errors
appendResult := func(t []templateName, err1 error) {
if err1 != nil {
Expand All @@ -53,21 +47,21 @@ func processNode(
}

if w, ok := node.(*parse.WithNode); ok && w != nil {
appendResult(processNode(parent, index, w.List, render, partial))
appendResult(processNode(parent, index, w.ElseList, render, partial))
appendResult(processNode(parent, index, w.List))
appendResult(processNode(parent, index, w.ElseList))
}
if l, ok := node.(*parse.ListNode); ok && l != nil {
for i, n := range l.Nodes {
appendResult(processNode(l, i, n, render, partial))
appendResult(processNode(l, i, n))
}
}
if i, ok := node.(*parse.IfNode); ok && i != nil {
appendResult(processNode(parent, index, i.List, render, partial))
appendResult(processNode(parent, index, i.ElseList, render, partial))
appendResult(processNode(parent, index, i.List))
appendResult(processNode(parent, index, i.ElseList))
}
if r, ok := node.(*parse.RangeNode); ok && r != nil {
appendResult(processNode(parent, index, r.List, render, partial))
appendResult(processNode(parent, index, r.ElseList, render, partial))
appendResult(processNode(parent, index, r.List))
appendResult(processNode(parent, index, r.ElseList))
}

return ts, err
Expand Down
Loading