Skip to content
Open
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.DS_Store
.idea
.idea
16 changes: 16 additions & 0 deletions constructors.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func (t *Template) newNil(pos Pos) *NilNode {
return &NilNode{NodeBase: NodeBase{TemplateName: t.Name, NodeType: NodeNil, Pos: pos}}
}

func (t *Template) newUndefined(pos Pos) *UndefinedNode {
return &UndefinedNode{NodeBase: NodeBase{TemplateName: t.Name, NodeType: NodeUndefined, Pos: pos}}
}

func (t *Template) newField(pos Pos, ident string) *FieldNode {
return &FieldNode{NodeBase: NodeBase{TemplateName: t.Name, NodeType: NodeField, Pos: pos}, Ident: strings.Split(ident[1:], ".")} //[1:] to drop leading period
}
Expand Down Expand Up @@ -114,6 +118,18 @@ func (t *Template) newElse(pos Pos, line int) *elseNode {
return &elseNode{NodeBase: NodeBase{TemplateName: t.Name, NodeType: nodeElse, Pos: pos, Line: line}}
}

func (t *Template) newFilter(pos Pos, line int, set *SetNode, pipe Expression, list, elseList *ListNode) *FilterNode {
return &FilterNode{BranchNode{NodeBase: NodeBase{TemplateName: t.Name, NodeType: NodeFilter, Pos: pos, Line: line}, Set: set, Expression: pipe, List: list, ElseList: elseList}}
}

func (t *Template) newCase(pos Pos, line int, pipe Expression, list *ListNode) *CaseNode {
return &CaseNode{BranchNode{NodeBase: NodeBase{TemplateName: t.Name, NodeType: NodeCase, Pos: pos, Line: line}, Expression: pipe, List: list}}
}

func (t *Template) newSwitch(pos Pos, line int, set *SetNode, pipe Expression, list, elseList *ListNode) *SwitchNode {
return &SwitchNode{BranchNode{NodeBase: NodeBase{TemplateName: t.Name, NodeType: NodeSwitch, Pos: pos, Line: line}, Set: set, Expression: pipe, List: list, ElseList: elseList}}
}

func (t *Template) newIf(pos Pos, line int, set *SetNode, pipe Expression, list, elseList *ListNode) *IfNode {
return &IfNode{BranchNode{NodeBase: NodeBase{TemplateName: t.Name, NodeType: NodeIf, Pos: pos, Line: line}, Set: set, Expression: pipe, List: list, ElseList: elseList}}
}
Expand Down
10 changes: 9 additions & 1 deletion default.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ func init() {
"unsafe": reflect.ValueOf(SafeWriter(unsafePrinter)),
"writeJson": reflect.ValueOf(jsonRenderer),
"json": reflect.ValueOf(json.Marshal),
"default": reflect.ValueOf(Func(func(a Arguments) reflect.Value {
a.RequireNumOfArguments("default", 1, -1)
return a.Get(0)
})),
"format": reflect.ValueOf(Func(func(a Arguments) reflect.Value {
a.RequireNumOfArguments("format", 1, -1)
return a.Get(0)
})),
"isset": reflect.ValueOf(Func(func(a Arguments) reflect.Value {
a.RequireNumOfArguments("isset", 1, -1)
for i := 0; i < len(a.argExpr); i++ {
Expand All @@ -76,7 +84,7 @@ func init() {
return reflect.ValueOf(expression.NumField())
}

a.Panicf("inválid value type %s in len builtin", expression.Type())
a.Panicf("invalid value type %s in len builtin", expression.Type())
return reflect.Value{}
})),
"includeIfExists": reflect.ValueOf(Func(func(a Arguments) reflect.Value {
Expand Down
Loading