本文整理汇总了Golang中text/template/parse.Node.Type方法的典型用法代码示例。如果您正苦于以下问题:Golang Node.Type方法的具体用法?Golang Node.Type怎么用?Golang Node.Type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类text/template/parse.Node
的用法示例。
在下文中一共展示了Node.Type方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: IsPseudoFunction
// IsPseudoFunction returns true iff n is a *parse.ActionNode
// consisting solely of a fn call without any arguments.
func IsPseudoFunction(n parse.Node, fn string) bool {
return n.Type() == parse.NodeAction && n.String() == leftDelim+fn+rightDelim
}
示例2: DataNode
func DataNode(root *template.Template, node parse.Node, data *Dotted, vars map[string][]string, prefixwords []string) {
if true {
switch node.Type() {
case parse.NodeWith:
withNode := node.(*parse.WithNode)
arg0 := withNode.Pipe.Cmds[0].Args[0].String()
var withv string
if len(arg0) > 0 && arg0[0] == '.' {
if decl := withNode.Pipe.Decl; len(decl) > 0 {
// just {{with $ := ...}} cases
withv = decl[0].Ident[0]
words := strings.Split(arg0[1:], ".")
vars[withv] = words
data.Append(words, prefixwords)
}
}
if withNode.List != nil {
for _, n := range withNode.List.Nodes {
DataNode(root, n, data, vars, prefixwords)
}
}
if withNode.ElseList != nil {
for _, n := range withNode.ElseList.Nodes {
DataNode(root, n, data, vars, prefixwords)
}
}
if withv != "" {
delete(vars, withv)
}
case parse.NodeTemplate:
tnode := node.(*parse.TemplateNode)
var tawords []string
for _, arg := range tnode.Pipe.Cmds[0].Args {
s := arg.String()
if len(s) > 1 && s[0] == '.' {
tawords = strings.Split(s[1:], ".")
data.Append(tawords, prefixwords)
break // just one argument (pipeline) to "{{template}}" allowed anyway
}
}
if sub := root.Lookup(tnode.Name); sub != nil && sub.Tree != nil && sub.Tree.Root != nil {
for _, n := range sub.Tree.Root.Nodes {
pw := prefixwords
if tawords != nil {
pw = append(prefixwords, tawords...)
}
DataNode(root, n, data, vars, pw)
}
}
case parse.NodeAction:
actionNode := node.(*parse.ActionNode)
decl := actionNode.Pipe.Decl
for _, cmd := range actionNode.Pipe.Cmds {
if cmd.NodeType != parse.NodeCommand {
continue
}
for _, arg := range cmd.Args {
var ident []string
switch arg.Type() {
case parse.NodeChain:
chain := arg.(*parse.ChainNode)
if chain.Node.Type() == parse.NodePipe {
pipe := chain.Node.(*parse.PipeNode)
for _, arg := range pipe.Cmds[0].Args {
if arg.Type() == parse.NodeField {
w := arg.String()
if len(w) > 0 && w[0] == '.' {
data.Append(strings.Split(w[1:], "."), prefixwords)
}
}
}
}
case parse.NodeField:
ident = arg.(*parse.FieldNode).Ident
if len(decl) > 0 && len(decl[0].Ident) > 0 {
vars[decl[0].Ident[0]] = ident
}
data.Append(ident, prefixwords)
case parse.NodeVariable:
ident = arg.(*parse.VariableNode).Ident
if words, ok := vars[ident[0]]; ok {
words := append(words, ident[1:]...)
data.Append(words, prefixwords)
if len(decl) > 0 && len(decl[0].Ident) > 0 {
vars[decl[0].Ident[0]] = words
}
}
}
}
}
case parse.NodeRange:
rangeNode := node.(*parse.RangeNode)
decl := rangeNode.Pipe.Decl[len(rangeNode.Pipe.Decl)-1].String()
keys := []string{}
//.........这里部分代码省略.........