View Source Ymlr (ymlr v4.1.0)
Encodes data into YAML documents using the Ymlr.Encoder
protocol.
Every document starts with a separator ("---") and can be enhanced with comments.
Link to this section Summary
Functions
Encodes a given data as YAML document with a separator ("---") at the beginning.
Encodes a given data as YAML document with a separator ("---") at the beginning. Raises if it cannot be encoded.
Encodes a given list of data as "---" separated YAML documents.
Encodes a given list of data as "---" separated YAML documents. Raises if it cannot be encoded.
Link to this section Types
Link to this section Functions
@spec document(document(), opts :: Ymlr.Encoder.opts()) :: {:ok, binary()} | {:error, binary()}
Encodes a given data as YAML document with a separator ("---") at the beginning.
Optinally you can pass a tuple with comment(s) and data as first argument.
options
Options
atoms
- when set totrue
, encodes atom map keys with a leading colon.
examples
Examples
iex> Ymlr.document(%{a: 1})
{:ok, "---\na: 1\n"}
iex> Ymlr.document(%{a: 1}, atoms: true)
{:ok, "---\n:a: 1\n"}
iex> Ymlr.document({"comment", %{a: 1}})
{:ok, "---\n# comment\na: 1\n"}
iex> Ymlr.document({["comment 1", "comment 2"], %{a: 1}})
{:ok, "---\n# comment 1\n# comment 2\na: 1\n"}
Encodes a given data as YAML document with a separator ("---") at the beginning. Raises if it cannot be encoded.
Optinally you can pass a tuple with comment(s) and data as first argument.
options
Options
atoms
- when set totrue
, encodes atom map keys with a leading colon.
examples
Examples
iex> Ymlr.document!(%{a: 1})
"---\na: 1\n"
iex> Ymlr.document!(%{a: 1}, atoms: true)
"---\n:a: 1\n"
iex> Ymlr.document!({"comment", %{a: 1}})
"---\n# comment\na: 1\n"
iex> Ymlr.document!({["comment 1", "comment 2"], %{a: 1}})
"---\n# comment 1\n# comment 2\na: 1\n"
@spec documents([document()], opts :: Ymlr.Encoder.opts()) :: {:ok, binary()} | {:error, binary()}
Encodes a given list of data as "---" separated YAML documents.
options
Options
atoms
- when set totrue
, encodes atom map keys with a leading colon.
examples
Examples
iex> Ymlr.documents([%{a: 1}])
{:ok, "---\na: 1\n"}
iex> Ymlr.documents([%{a: 1}], atoms: true)
{:ok, "---\n:a: 1\n"}
iex> Ymlr.documents([%{a: 1}, %{b: 2}])
{:ok, "---\na: 1\n\n---\nb: 2\n"}
iex> Ymlr.documents(%{a: "a"})
{:error, "The given argument is not a list of documents. Use document/1, document/2, document!/1 or document!/2 for a single document."}
Encodes a given list of data as "---" separated YAML documents. Raises if it cannot be encoded.
options
Options
atoms
- when set totrue
, encodes atom map keys with a leading colon.
examples
Examples
iex> Ymlr.documents!([%{a: 1}])
"---\na: 1\n"
iex> Ymlr.documents!([%{a: 1}], atoms: true)
"---\n:a: 1\n"
iex> Ymlr.documents!([%{a: 1}, %{b: 2}])
"---\na: 1\n\n---\nb: 2\n"
iex> Ymlr.documents!(%{a: "a"})
** (ArgumentError) The given argument is not a list of documents. Use document/1, document/2, document!/1 or document!/2 for a single document.