Kuddle (Kuddle v1.1.0) View Source

Kuddle is a KDL (https://github.com/kdl-org/kdl) encoder and decoder.

It is compliant with both the 1.x and 2.x specifications, simply use the appropriately versioned module for your needs.

And yes UTF-8 still works.

V2 is the default.

Link to this section Summary

Functions

Decode a KDL document into kuddle nodes

Decode a KDL blob into kuddle nodes, if the blob is not a valid KDL document this will raise a Kuddle.DecodeError.

Encode a kuddle document as serialized KDL

Encode a kuddle document as serialized KDL, if the document cannot be encoded a Kuddle.EncodeError will be raised.

Select allows searching a document for particular nodes by name, and or attributes.

Link to this section Types

Link to this section Functions

Specs

decode(String.t()) :: {:ok, document(), rest :: tokens()} | {:error, term()}

Decode a KDL document into kuddle nodes

Usage

Kuddle.decode(blob)
{:ok, [%Kuddle.Node{name: "node"}], []} = Kuddle.decode("node")

Examples

iex> Kuddle.decode("node { node2 1; }")
{:ok, [%Kuddle.Node{name: "node", children: [%Kuddle.Node{name: "node2", attributes: [%Kuddle.Value{type: :integer, value: 1, format: :dec}]}]}], []}

Specs

decode!(String.t()) :: document()

Decode a KDL blob into kuddle nodes, if the blob is not a valid KDL document this will raise a Kuddle.DecodeError.

Usage

Kuddle.decode!(blob)
[%Kuddle.Node{name: "node"}] = Kuddle.decode!("node")

Examples

iex> Kuddle.decode!("node")
[%Kuddle.Node{name: "node"}]
Link to this function

encode(doc, options \\ [])

View Source

Specs

encode(document(), Keyword.t()) :: {:ok, String.t()} | {:error, term()}

Encode a kuddle document as serialized KDL

Usage

Kuddle.encode(kdl_document)
"node" = Kuddle.encode([%Kuddle.Node{name: "node"}])

Examples

iex> Kuddle.encode([%Kuddle.Node{name: "node"}])
{:ok, "node\n"}
Link to this function

encode!(doc, options \\ [])

View Source

Specs

encode!(document(), Keyword.t()) :: String.t()

Encode a kuddle document as serialized KDL, if the document cannot be encoded a Kuddle.EncodeError will be raised.

Usage

"node" = Kuddle.encode!([%Kuddle.Node{name: "node"}])

Examples

iex> Kuddle.encode!([%Kuddle.Node{name: "node"}])
"node\n"

Specs

select(document(), Kuddle.Path.path()) :: document()

Select allows searching a document for particular nodes by name, and or attributes.

Usage

Kuddle.select(kdl_document, path)
[%Kuddle.Node{name: "node"}] = Kuddle.select(document, ["node"])

Examples

iex> document = Kuddle.decode!("node; node2; node3")
[%Kuddle.Node{name: "node"}, %Kuddle.Node{name: "node2"}, %Kuddle.Node{name: "node3"}]
iex> Kuddle.select(document, ["node"])
[%Kuddle.Node{name: "node"}]