Writes the TOML of a generated config file, for
Sovite.Core.Postfix.Migration. Only what a Sovite config needs:
strings, integers, booleans, arrays of those, inline tables, tables,
and arrays of tables, with comments.
Summary
Types
A key and its value, optionally with a comment written above it.
A part of the document. Top-level :entries must come before the tables.
A value: string, integer, boolean, an array, or {:inline, pairs}.
Functions
A key: bare when it only has letters, digits, _, and -, otherwise
quoted.
Renders parts. Tables without entries are left out; each array table
is written, even when empty. A table's comment goes after its header.
A basic string, with \, ", and control characters escaped.
Invalid UTF-8 is replaced.
A value.
Wraps text into lines of at most width characters, at spaces.
Types
A key and its value, optionally with a comment written above it.
@type part() :: {:comment, String.t()} | {:entries, [entry()]} | {:table, String.t(), [entry()]} | {:table, String.t(), [entry()], String.t() | nil} | {:array_table, String.t(), [entry()]} | {:array_table, String.t(), [entry()], String.t() | nil}
A part of the document. Top-level :entries must come before the tables.
@type value() :: String.t() | integer() | boolean() | [String.t() | integer()] | {:inline, [{String.t(), value()}]}
A value: string, integer, boolean, an array, or {:inline, pairs}.
Functions
A key: bare when it only has letters, digits, _, and -, otherwise
quoted.
iex> Sovite.Core.Postfix.TomlWriter.key("alice@example.com")
~s("alice@example.com")
Renders parts. Tables without entries are left out; each array table
is written, even when empty. A table's comment goes after its header.
A basic string, with \, ", and control characters escaped.
Invalid UTF-8 is replaced.
iex> Sovite.Core.Postfix.TomlWriter.string(~s(a "b" \\ c\td))
~S("a \"b\" \\ c\td")
A value.
@spec wrap(String.t(), pos_integer()) :: [String.t()]
Wraps text into lines of at most width characters, at spaces.