2017-07-06 15:21:26 +02:00
|
|
|
package render
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
2022-01-06 18:43:17 +01:00
|
|
|
"github.com/danog/liquid/expressions"
|
|
|
|
"github.com/danog/liquid/parser"
|
2017-07-06 15:21:26 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
2017-07-06 15:21:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// BlockNode represents a {% tag %}…{% endtag %}.
|
|
|
|
type BlockNode struct {
|
2017-07-09 17:18:35 +02:00
|
|
|
parser.Token
|
2017-07-06 15:21:26 +02:00
|
|
|
renderer func(io.Writer, Context) error
|
|
|
|
Body []Node
|
2017-07-12 14:57:43 +02:00
|
|
|
Clauses []*BlockNode
|
2017-07-06 15:21:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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:21:26 +02:00
|
|
|
}
|
|
|
|
|
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
|
2017-07-06 15:21:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// TextNode is a text chunk, that is rendered verbatim.
|
|
|
|
type TextNode struct {
|
2017-07-09 17:18:35 +02:00
|
|
|
parser.Token
|
2017-07-06 15:21:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2017-07-06 15:21:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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")
|
2017-07-06 15:21:26 +02:00
|
|
|
}
|