2017-06-26 09:43:09 -04:00
|
|
|
package chunks
|
|
|
|
|
2017-06-26 12:41:41 -04:00
|
|
|
import (
|
|
|
|
"fmt"
|
2017-06-26 09:43:09 -04:00
|
|
|
|
2017-06-26 12:41:41 -04:00
|
|
|
yaml "gopkg.in/yaml.v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MustYAML returns the YAML of an interface.
|
2017-06-26 09:43:09 -04:00
|
|
|
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.
|
2017-06-26 09:43:09 -04:00
|
|
|
func (n ASTControlTag) MarshalYAML() (interface{}, error) {
|
|
|
|
return map[string]map[string]interface{}{
|
2017-06-27 12:23:07 -04:00
|
|
|
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,
|
2017-06-26 09:43:09 -04:00
|
|
|
}}, nil
|
|
|
|
}
|
|
|
|
|
2017-06-26 12:41:41 -04:00
|
|
|
// MarshalYAML marshalls a chunk for debugging.
|
2017-06-26 09:43:09 -04:00
|
|
|
func (n ASTText) MarshalYAML() (interface{}, error) {
|
2017-06-27 11:19:12 -04:00
|
|
|
return n.Chunk.MarshalYAML()
|
2017-06-26 09:43:09 -04:00
|
|
|
}
|
|
|
|
|
2017-06-26 12:41:41 -04:00
|
|
|
// MarshalYAML marshalls a chunk for debugging.
|
2017-06-26 09:43:09 -04:00
|
|
|
func (n ASTObject) MarshalYAML() (interface{}, error) {
|
2017-06-27 11:19:12 -04:00
|
|
|
return n.Chunk.MarshalYAML()
|
2017-06-26 09:43:09 -04:00
|
|
|
}
|