Macaw.Draw.Render.Target behaviour (macaw_draw v0.1.0)

Copy Markdown View Source

The behavior of a rendering target (spec/10 §2.2), visualize's Visualize.Backend: what Macaw.Draw.Render.render/3 dispatches a path, a node and a list of nodes to.

Each callback answers {:ok, output} or {:error, faults}, a fault {path, reason} with the path the child indexes from the root (spec/10 §2.5); a target never raises on a scene. wrap_root/2 is optional: a target that writes a document around a list of nodes implements it.

Summary

Types

A refusal: faults with their paths.

A target's output: markup, a command list, a byte stream.

Callbacks

A node and everything under it.

A path written alone, with the target's options.

A list of nodes, a whole scene.

Written output wrapped in the target's document.

Types

error()

@type error() :: {:error, [Macaw.Base.Fault.t()]}

A refusal: faults with their paths.

output()

@type output() :: iodata() | [term()]

A target's output: markup, a command list, a byte stream.

Callbacks

render_node(t, keyword)

@callback render_node(Macaw.Draw.IR.Element.t(), keyword()) :: {:ok, output()} | error()

A node and everything under it.

render_path(t, keyword)

@callback render_path(Macaw.Draw.IR.Path.t(), keyword()) :: {:ok, output()} | error()

A path written alone, with the target's options.

render_scene(list, keyword)

@callback render_scene([Macaw.Draw.IR.Element.t()], keyword()) ::
  {:ok, output()} | error()

A list of nodes, a whole scene.

wrap_root(output, keyword)

(optional)
@callback wrap_root(output(), keyword()) :: {:ok, output()} | error()

Written output wrapped in the target's document.