MCPcopy Index your code
hub / github.com/abiosoft/mold / processActionNode

Function processActionNode

process.go:68–115  ·  view source on GitHub ↗
(root *templateFile, parent *parse.ListNode, index int, node parse.Node, funcName string)

Source from the content-addressed store, hash-verified

66}
67
68func 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
117func invalidFuncType(typ templateType, funcName string) bool {
118 switch typ {

Callers 1

processNodeFunction · 0.85

Calls 3

getActionArgsFunction · 0.85
invalidFuncTypeFunction · 0.85
StringMethod · 0.80

Tested by

no test coverage detected