Lossless writer for OKF bundles.
Preserves unknown frontmatter keys via ExOKF.Concept.frontmatter_map/1 and
writes reserved index/log documents from their stored bodies.
Summary
Functions
Serializes a single concept to an OKF markdown document string.
Serializes an index document to markdown.
Serializes a log document to markdown.
Writes a bundle to destination.
Functions
@spec dump_concept(ExOKF.Concept.t()) :: String.t()
Serializes a single concept to an OKF markdown document string.
Parameters
concept(ExOKF.Concept.t()) — concept to serialize
Returns
A UTF-8 string with YAML frontmatter fences and the markdown body.
Examples
iex> c = %ExOKF.Concept{id: "x", path: "x.md", type: "Metric", title: "X", body: "hi\n"}
iex> doc = ExOKF.Writer.dump_concept(c)
iex> String.starts_with?(doc, "---\n") and String.contains?(doc, "type: Metric")
true
@spec dump_index(ExOKF.Index.t()) :: String.t()
Serializes an index document to markdown.
When frontmatter is present (root okf_version declaration), it is
written as a YAML fence; otherwise only body is emitted.
Parameters
index(ExOKF.Index.t()) — index to serialize
Examples
iex> ExOKF.Writer.dump_index(%ExOKF.Index{path: "index.md", directory: "", body: "# Hi\n"})
"# Hi\n"
@spec dump_log(ExOKF.Log.t()) :: String.t()
Serializes a log document to markdown.
Parameters
log(ExOKF.Log.t()) — log to serialize
Examples
iex> ExOKF.Writer.dump_log(%ExOKF.Log{path: "log.md", directory: "", body: "# Log\n"})
"# Log\n"
@spec write(ExOKF.Bundle.t(), String.t()) :: :ok | {:error, term()}
Writes a bundle to destination.
Creates the directory tree as needed. Concepts, indexes, and logs are written under their relative paths.
Parameters
bundle(ExOKF.Bundle.t()) — in-memory bundle to persistdestination(String.t()) — output directory path
Returns
:ok— all files written{:error, term()}— filesystem error fromFile.mkdir_p/1orFile.write/2
Examples
iex> bundle = ExOKF.TestSupport.minimal_bundle()
iex> dest = Path.join(System.tmp_dir!(), "ex_okf_doc_write_" <> Integer.to_string(:erlang.phash2(make_ref())))
iex> ExOKF.Writer.write(bundle, dest)
:ok
iex> File.exists?(Path.join(dest, "hello.md"))
true