Dumper

struct Dumper {
Resolver resolver;
bool canonical;
uint textWidth;
LineBreak lineBreak;
string YAMLVersion;
bool explicitStart;
bool explicitEnd;
string name;
ScalarStyle defaultScalarStyle;
CollectionStyle defaultCollectionStyle;
}

Members

Functions

dump
void dump(Range range, Node[] documents...)

Dump one or more YAML _documents to the file/stream.

indent
void indent(uint indent)

Set indentation width. 2 by default. Must not be zero.

tagDirectives
void tagDirectives(string[string] tags)

Specify tag directives.

Examples

Write to a file

auto node = Node([1, 2, 3, 4, 5]);
dumper().dump(new Appender!string(), node);

Write multiple YAML documents to a file

1 auto node1 = Node([1, 2, 3, 4, 5]);
2 auto node2 = Node("This document contains only one string");
3 dumper().dump(new Appender!string(), node1, node2);
4 //Or with an array:
5 dumper().dump(new Appender!string(), [node1, node2]);

Write to memory

auto stream = new Appender!string();
auto node = Node([1, 2, 3, 4, 5]);
dumper().dump(stream, node);

Use a custom resolver to support custom data types and/or implicit tags

1 import std.regex : regex;
2 auto node = Node([1, 2, 3, 4, 5]);
3 auto dumper = dumper();
4 dumper.resolver.addImplicitResolver("!tag", regex("A.*"), "A");
5 dumper.dump(new Appender!string(), node);

Set default scalar style

1 auto stream = new Appender!string();
2 auto node = Node("Hello world!");
3 auto dumper = dumper();
4 dumper.defaultScalarStyle = ScalarStyle.singleQuoted;
5 dumper.dump(stream, node);

Set default collection style

1 auto stream = new Appender!string();
2 auto node = Node(["Hello", "world!"]);
3 auto dumper = dumper();
4 dumper.defaultCollectionStyle = CollectionStyle.flow;
5 dumper.dump(stream, node);

Meta