1
0
mirror of https://github.com/danog/liquid.git synced 2024-11-30 10:39:01 +01:00
liquid/chunk_ast.go

64 lines
1020 B
Go

package main
import (
"io"
yaml "gopkg.in/yaml.v2"
)
type AST interface {
Render(io.Writer, Context) error
}
type ASTSeq struct {
Children []AST
}
type ASTChunks struct {
chunks []Chunk
}
type ASTText struct {
chunk Chunk
}
type ASTObject struct {
chunk Chunk
}
type ASTControlTag struct {
chunk Chunk
cd *ControlTagDefinition
body []AST
branches []*ASTControlTag
}
func MustYAML(val interface{}) string {
b, err := yaml.Marshal(val)
if err != nil {
panic(err)
}
return string(b)
}
func (n ASTChunks) MarshalYAML() (interface{}, error) {
return map[string]interface{}{"leaf": n.chunks}, nil
}
func (n ASTControlTag) MarshalYAML() (interface{}, error) {
return map[string]map[string]interface{}{
n.cd.Name: {
"args": n.chunk.Args,
"body": n.body,
"branches": n.branches,
}}, nil
}
func (n ASTText) MarshalYAML() (interface{}, error) {
return n.chunk.MarshalYAML()
}
func (n ASTObject) MarshalYAML() (interface{}, error) {
return n.chunk.MarshalYAML()
}