Dumper

Undocumented in source.

Members

Functions

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

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

opCmp
int opCmp(Dumper )
Undocumented in source.
opEquals
bool opEquals(Dumper )
Undocumented in source.

Properties

indent
uint indent [@property setter]

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

tagDirectives
string[string] tagDirectives [@property setter]

Specify tag directives.

Variables

YAMLVersion
string YAMLVersion;
Undocumented in source.
canonical
bool canonical;
Undocumented in source.
defaultCollectionStyle
CollectionStyle defaultCollectionStyle;
Undocumented in source.
defaultScalarStyle
ScalarStyle defaultScalarStyle;
Undocumented in source.
explicitEnd
bool explicitEnd;
Undocumented in source.
explicitStart
bool explicitStart;
Undocumented in source.
lineBreak
LineBreak lineBreak;
Undocumented in source.
name
string name;
Undocumented in source.
resolver
Resolver resolver;
Undocumented in source.
textWidth
uint textWidth;
Undocumented in source.

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

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

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

Set default scalar style

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

Set default collection style

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

Meta