(root *templateFile, parent *parse.ListNode, index int, node parse.Node, funcName string)
| 66 | } |
| 67 | |
| 68 | func processActionNode(root *templateFile, parent *parse.ListNode, index int, node parse.Node, funcName string) error { |
| 69 | actionNode := node.(*parse.ActionNode) |
| 70 | cmd := actionNode.Pipe.Cmds[0] |
| 71 | _, name, field := getActionArgs(cmd) |
| 72 | |
| 73 | if name == root.Name() { |
| 74 | return posErr{pos: int(actionNode.Pos), message: "cyclic reference"} |
| 75 | } |
| 76 | |
| 77 | // validate for view and partial |
| 78 | if invalidFuncType(root.typ, funcName) { |
| 79 | return posErr{pos: int(actionNode.Pos), message: fmt.Sprintf("%s not supported", funcName)} |
| 80 | } |
| 81 | |
| 82 | var arg parse.Node = &parse.DotNode{} |
| 83 | |
| 84 | // only handle if the function name is render or partial |
| 85 | switch { |
| 86 | case funcName == partialFunc.String(): |
| 87 | if field != nil { |
| 88 | arg = field |
| 89 | } |
| 90 | if name == "" { |
| 91 | return posErr{pos: int(actionNode.Pos), message: `path to partial file is not specified`} |
| 92 | } |
| 93 | case funcName == renderFunc.String(): |
| 94 | if name == "" { |
| 95 | name = "body" |
| 96 | } |
| 97 | default: |
| 98 | return nil |
| 99 | } |
| 100 | |
| 101 | cmd.Args = []parse.Node{arg} |
| 102 | actionNode.Pipe.Cmds = []*parse.CommandNode{cmd} |
| 103 | |
| 104 | tn := &parse.TemplateNode{ |
| 105 | NodeType: parse.NodeTemplate, |
| 106 | Pos: actionNode.Pos, |
| 107 | Line: actionNode.Line, |
| 108 | Name: name, |
| 109 | Pipe: actionNode.Pipe, |
| 110 | } |
| 111 | |
| 112 | // replace the ActionNode with a TemplateNode. |
| 113 | parent.Nodes[index] = tn |
| 114 | return nil |
| 115 | } |
| 116 | |
| 117 | func invalidFuncType(typ templateType, funcName string) bool { |
| 118 | switch typ { |
no test coverage detected