Kuddle.V1 (Kuddle v1.1.0) View Source

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

Kuddle is KDL 1.0.0 compliant and should be able to process most if not all KDL documents without issue.

And yes UTF-8 works.

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

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

Examples

iex> Kuddle.V1.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.Node{name: "node"}] = Kuddle.V1.decode!("node")

Examples

iex> Kuddle.V1.decode!("node")
[%Kuddle.Node{name: "node"}]

Specs

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

Encode a kuddle document as serialized KDL

Usage

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

Examples

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

Specs

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

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

Usage

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

Examples

iex> Kuddle.V1.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.Node{name: "node"}] = Kuddle.V1.select(document, ["node"])

Examples

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