public struct Dumper

Dumps YAML documents to files or streams.

User specified Representer and/or Resolver can be used to support new tags / data types.

Setters are provided to affect output details (style, encoding, etc.).

Examples

Write to a file:
auto node = Node([1, 2, 3, 4, 5]);
Dumper("file.yaml").dump(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("file.yaml").dump(node1, node2);

//Or with an array:
//Dumper("file.yaml").dump([node1, node2]);

Write to memory:
import std.stream;
auto stream = new MemoryStream();
auto node = Node([1, 2, 3, 4, 5]);
Dumper(stream).dump(node);
Use a custom representer/resolver to support custom data types and/or implicit tags:
auto node = Node([1, 2, 3, 4, 5]);
auto representer = new Representer();
auto resolver = new Resolver();

//Add representer functions / resolver expressions here...

auto dumper = Dumper("file.yaml");
dumper.representer = representer;
dumper.resolver = resolver;
dumper.dump(node);
public this(string filename) @trusted

Construct a Dumper writing to a file.

Parameters

filename

File name to write to.

Throws

YAMLException if the file can not be dumped to (e.g. cannot be opened).

public this(Stream stream) @safe

Construct a Dumper writing to a _stream. This is useful to e.g. write to memory.

public @property void name(string name) pure @safe nothrow

Set stream _name. Used in debugging messages.

public @property void resolver(Resolver resolver) @trusted

Specify custom Resolver to use.

public @property void representer(Representer representer) @trusted

Specify custom Representer to use.

public @property void canonical(bool canonical) pure @safe nothrow

Write scalars in _canonical form?

public @property void indent(uint indent) pure @safe nothrow

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

Contracts

in
{
    assert (indent != 0, "Can't use zero YAML indent width");
}
public @property void textWidth(uint width) pure @safe nothrow

Set preferred text _width.

public @property void lineBreak(LineBreak lineBreak) pure @safe nothrow

Set line break to use. Unix by default.

public @property void encoding(Encoding encoding) pure @safe nothrow

Set character _encoding to use. UTF-8 by default.

public @property void explicitStart(bool explicit) pure @safe nothrow

Always explicitly write document start?

public @property void explicitEnd(bool explicit) pure @safe nothrow

Always explicitly write document end?

public @property void YAMLVersion(string YAMLVersion) pure @safe nothrow

Specify YAML version string. "1.1" by default.

public @property void tagDirectives(string[string] tags) pure @trusted

Specify tag directives.

A tag directive specifies a shorthand notation for specifying _tags. Each tag directive associates a handle with a prefix. This allows for compact tag notation.

Each handle specified MUST start and end with a '!' character (a single character "!" handle is allowed as well).

Only alphanumeric characters, '-', and '__' may be used in handles.

Each prefix MUST not be empty.

The "!!" handle is used for default YAML _tags with prefix

"tag

yaml.org,2002:". This can be overridden.

Parameters

tags

Tag directives (keys are handles, values are prefixes).

Example

Dumper dumper = Dumper("file.yaml");
string[string] directives;
directives["!short!"] = "tag:long.org,2011:";
//This will emit tags starting with "tag:long.org,2011"
//with a "!short!" prefix instead.
dumper.tagDirectives(directives);
dumper.dump(Node("foo"));
public void dump(Node[] documents...) @trusted

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

Note that while you can call dump() multiple times on the same dumper, you will end up writing multiple YAML "files" to the same file/stream.

Parameters

documents

Documents to _dump (root nodes of the _documents).

Throws

YAMLException on error (e.g. invalid nodes, unable to write to file/stream).

Functions

this

Construct a Dumper writing to a file.

this

Construct a Dumper writing to a _stream. This is useful to e.g. write to memory.

@propertynamepure, @safe, nothrow

Set stream _name. Used in debugging messages.

@propertyresolver@trusted

Specify custom Resolver to use.

@propertyrepresenter@trusted

Specify custom Representer to use.

@propertycanonicalpure, @safe, nothrow

Write scalars in _canonical form?

@propertyindentpure, @safe, nothrow

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

@propertytextWidthpure, @safe, nothrow

Set preferred text _width.

@propertylineBreakpure, @safe, nothrow

Set line break to use. Unix by default.

@propertyencodingpure, @safe, nothrow

Set character _encoding to use. UTF-8 by default.

@propertyexplicitStartpure, @safe, nothrow

Always explicitly write document start?

@propertyexplicitEndpure, @safe, nothrow

Always explicitly write document end?

@propertyYAMLVersionpure, @safe, nothrow

Specify YAML version string. "1.1" by default.

@propertytagDirectivespure, @trusted

Specify tag directives.

dump@trusted

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