Example #1
0
// clone clones a template Node.
func clone(n parse.Node) parse.Node {
	switch t := n.(type) {
	case *parse.ActionNode:
		return cloneAction(t)
	case *parse.IfNode:
		b := new(parse.IfNode)
		copyBranch(&b.BranchNode, &t.BranchNode)
		return b
	case *parse.ListNode:
		return cloneList(t)
	case *parse.RangeNode:
		b := new(parse.RangeNode)
		copyBranch(&b.BranchNode, &t.BranchNode)
		return b
	case *parse.TemplateNode:
		return cloneTemplate(t)
	case *parse.TextNode:
		return cloneText(t)
	case *parse.WithNode:
		b := new(parse.WithNode)
		copyBranch(&b.BranchNode, &t.BranchNode)
		return b
	}
	panic("cloning " + n.String() + " is unimplemented")
}
Example #2
0
// escape escapes a template node.
func escape(c context, n parse.Node) context {
	switch n := n.(type) {
	case *parse.ActionNode:
		return escapeAction(c, n)
	case *parse.IfNode:
		return escapeBranch(c, &n.BranchNode, "if")
	case *parse.ListNode:
		return escapeList(c, n)
	case *parse.RangeNode:
		return escapeBranch(c, &n.BranchNode, "range")
	case *parse.TextNode:
		return escapeText(c, n.Text)
	case *parse.WithNode:
		return escapeBranch(c, &n.BranchNode, "with")
	}
	// TODO: handle a *parse.TemplateNode. Should Escape take a *template.Set?
	panic("escaping " + n.String() + " is unimplemented")
}
Example #3
0
// escape escapes a template node.
func (e *escaper) escape(c context, n parse.Node) context {
	switch n := n.(type) {
	case *parse.ActionNode:
		return e.escapeAction(c, n)
	case *parse.IfNode:
		return e.escapeBranch(c, &n.BranchNode, "if")
	case *parse.ListNode:
		return e.escapeList(c, n)
	case *parse.RangeNode:
		return e.escapeBranch(c, &n.BranchNode, "range")
	case *parse.TemplateNode:
		return e.escapeTemplate(c, n)
	case *parse.TextNode:
		return e.escapeText(c, n)
	case *parse.WithNode:
		return e.escapeBranch(c, &n.BranchNode, "with")
	}
	panic("escaping " + n.String() + " is unimplemented")
}
Example #4
0
// escapeNode dispatches to escape<NodeType> helpers by type.
func escapeNode(node parse.Node) {
	switch n := node.(type) {
	case *parse.ListNode:
		escapeListNode(n)
	case *parse.TextNode:
		// Nothing to do.
	case *parse.ActionNode:
		escapeActionNode(n)
	case *parse.IfNode:
		escapeIfNode(n)
	case *parse.RangeNode:
		escapeRangeNode(n)
	case *parse.TemplateNode:
		// Nothing to do.
	case *parse.WithNode:
		escapeWithNode(n)
	default:
		panic("handling for " + node.String() + " not implemented")
		// TODO: Handle other inner node types.
	}
}