| 418 | } |
| 419 | |
| 420 | func (b *BranchNode) String() string { |
| 421 | |
| 422 | if b.NodeType == NodeRange { |
| 423 | s := "" |
| 424 | if b.Set != nil { |
| 425 | s = b.Set.String() |
| 426 | } else { |
| 427 | s = b.Expression.String() |
| 428 | } |
| 429 | |
| 430 | if b.ElseList != nil { |
| 431 | return fmt.Sprintf("{{range %s}}%s{{else}}%s{{end}}", s, b.List, b.ElseList) |
| 432 | } |
| 433 | return fmt.Sprintf("{{range %s}}%s{{end}}", s, b.List) |
| 434 | } else { |
| 435 | s := "" |
| 436 | if b.Set != nil { |
| 437 | s = b.Set.String() + ";" |
| 438 | } |
| 439 | if b.ElseList != nil { |
| 440 | return fmt.Sprintf("{{if %s%s}}%s{{else}}%s{{end}}", s, b.Expression, b.List, b.ElseList) |
| 441 | } |
| 442 | return fmt.Sprintf("{{if %s%s}}%s{{end}}", s, b.Expression, b.List) |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | // IfNode represents an {{if}} action and its commands. |
| 447 | type IfNode struct { |