Kuddle.V2 (Kuddle v1.1.0) View Source

This is the V2 interface which handles KDL2 documents, if you need the older encoder and encoder, see the V1 module instead.

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.V2.decode(document)
{:ok, [%Kuddle.Node{name: "node"}], []} = Kuddle.V2.decode("node")

Examples

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

Examples

iex> Kuddle.V2.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

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

Examples

iex> Kuddle.V2.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.V2.encode!([%Kuddle.Node{name: "node"}])

Examples

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

Examples

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