1
0
mirror of https://github.com/danog/liquid.git synced 2024-11-30 06:28:58 +01:00
liquid/render/nodes.go

64 lines
1.3 KiB
Go
Raw Permalink Normal View History

package render
import (
"io"
2022-01-06 18:43:17 +01:00
"github.com/danog/liquid/expressions"
"github.com/danog/liquid/parser"
)
// Node is a node of the render tree.
type Node interface {
2017-07-10 17:49:14 +02:00
SourceLocation() parser.SourceLoc // for error reporting
2017-07-12 14:57:43 +02:00
SourceText() string // for error reporting
2017-07-16 23:43:04 +02:00
render(*trimWriter, nodeContext) Error
}
// BlockNode represents a {% tag %}…{% endtag %}.
type BlockNode struct {
2017-07-09 17:18:35 +02:00
parser.Token
renderer func(io.Writer, Context) error
Body []Node
2017-07-12 14:57:43 +02:00
Clauses []*BlockNode
}
// RawNode holds the text between the start and end of a raw tag.
type RawNode struct {
slices []string
2017-07-10 17:49:14 +02:00
sourcelessNode
}
2017-07-06 15:40:37 +02:00
// TagNode renders itself via a render function that is created during parsing.
type TagNode struct {
2017-07-09 17:18:35 +02:00
parser.Token
2017-07-06 15:40:37 +02:00
renderer func(io.Writer, Context) error
}
// TextNode is a text chunk, that is rendered verbatim.
type TextNode struct {
2017-07-09 17:18:35 +02:00
parser.Token
}
// ObjectNode is an {{ object }} object.
type ObjectNode struct {
2017-07-09 17:18:35 +02:00
parser.Token
2017-07-14 02:18:23 +02:00
expr expressions.Expression
}
// SeqNode is a sequence of nodes.
type SeqNode struct {
Children []Node
2017-07-10 17:49:14 +02:00
sourcelessNode
}
// FIXME requiring this is a bad design
type sourcelessNode struct{}
func (n *sourcelessNode) SourceLocation() parser.SourceLoc {
panic("unexpected call on sourceless node")
}
func (n *sourcelessNode) SourceText() string {
panic("unexpected call on sourceless node")
}