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

51 lines
1.1 KiB
Go
Raw Normal View History

package chunks
2017-06-26 12:41:41 -04:00
import (
"fmt"
2017-06-26 12:41:41 -04: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 12:41:41 -04: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:
2017-06-30 17:33:36 -04:00
return map[string]interface{}{"tag": c.Name, "args": c.Args}, nil
2017-06-26 12:41:41 -04:00
case ObjChunkType:
2017-06-29 12:20:16 -04:00
return map[string]interface{}{"obj": c.Name}, nil
2017-06-26 12:41:41 -04:00
default:
return nil, fmt.Errorf("unknown chunk tag type: %v", c.Type)
}
}
// MarshalYAML marshalls a chunk for debugging.
func (n ASTControlTag) MarshalYAML() (interface{}, error) {
return map[string]map[string]interface{}{
n.cd.name: {
2017-06-30 17:33:36 -04:00
"args": n.Args,
2017-06-27 11:39:32 -04:00
"body": n.Body,
"branches": n.Branches,
}}, nil
}
2017-06-26 12:41:41 -04:00
// MarshalYAML marshalls a chunk for debugging.
func (n ASTText) MarshalYAML() (interface{}, error) {
2017-06-27 11:19:12 -04:00
return n.Chunk.MarshalYAML()
}
2017-06-26 12:41:41 -04:00
// MarshalYAML marshalls a chunk for debugging.
func (n ASTObject) MarshalYAML() (interface{}, error) {
2017-06-27 11:19:12 -04:00
return n.Chunk.MarshalYAML()
}