1
0
mirror of https://github.com/danog/liquid.git synced 2025-01-06 01:58:22 +01:00
liquid/chunks/marshal.go

56 lines
1.3 KiB
Go
Raw Normal View History

package chunks
2017-06-26 18:41:41 +02:00
import (
"fmt"
2017-06-26 18:41:41 +02:00
yaml "gopkg.in/yaml.v2"
)
// MustYAML returns the YAML of an interface.
func MustYAML(val interface{}) string {
b, err := yaml.Marshal(val)
if err != nil {
panic(err)
}
return string(b)
}
2017-06-26 18:41:41 +02:00
// MarshalYAML is for debugging.
func (c Chunk) MarshalYAML() (interface{}, error) {
switch c.Type {
case TextChunkType:
return map[string]interface{}{"text": c.Source}, nil
case TagChunkType:
return map[string]interface{}{"tag": c.Tag, "args": c.Args}, nil
case ObjChunkType:
return map[string]interface{}{"obj": c.Tag}, nil
default:
return nil, fmt.Errorf("unknown chunk tag type: %v", c.Type)
}
}
// MarshalYAML marshalls a chunk for debugging.
func (n ASTChunks) MarshalYAML() (interface{}, error) {
2017-06-26 18:41:41 +02:00
return map[string]interface{}{"chunks": n.chunks}, nil
}
2017-06-26 18:41:41 +02:00
// MarshalYAML marshalls a chunk for debugging.
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
}
2017-06-26 18:41:41 +02:00
// MarshalYAML marshalls a chunk for debugging.
func (n ASTText) MarshalYAML() (interface{}, error) {
return n.chunk.MarshalYAML()
}
2017-06-26 18:41:41 +02:00
// MarshalYAML marshalls a chunk for debugging.
func (n ASTObject) MarshalYAML() (interface{}, error) {
return n.chunk.MarshalYAML()
}