StatifierBlocks.Describe.Phrasing behaviour (StatifierBlocks v0.36.1)

Copy Markdown View Source

The seam a host rewords a described document through (ADR-0016 decision 3).

StatifierBlocks.Describe.render/2 writes a default line for every node and every edge. With phrasing: module, a module implementing this behaviour, each line is then offered to the callback for its node's kind or its edge's kind, handed the structured StatifierBlocks.Describe.Node or StatifierBlocks.Describe.Edge and the default line, and the callback answers its own line or :default.

CallbackAsked for
step/2, arm/2, rail/2, tray/2a node of that kind
entry/2, sequence/2, branch/2, interrupt/2, exit/2an edge of that kind

Every callback is optional; an undeclared one keeps the default line.

What an answer must be

A line, held to the refusal set StatifierBlocks.BlockType.sentence/2 holds a type's sentence/1 to. A refused answer falls back to the default line for that one node or edge, never to an error:

The callbackThe line
answers a non-blank binary carrying no newline, carriage return or tabthat binary, verbatim, uncapped
answers :defaultthe default line
answers a blank binary, one carrying a newline, carriage return or tab, or any other termthe default line
raises, throws or exitsthe default line

The seam rewords lines. It does not add, drop or reorder them, and it never sees or changes the structure StatifierBlocks.Describe.outline/3 answered. For the render to stay byte-identical for equal input, a callback has to be a pure function of its arguments; that half of the contract is the host's.

Summary

Types

A callback's answer: its own line, or :default for the default line.

Callbacks

The line for a node in one of its parent's side-by-side columns.

The line for a :branch edge.

The line for an :entry edge.

The line for an :exit edge.

The line for an :interrupt edge.

The line for a node on one of its parent's rails.

The line for a :sequence edge.

The line for a node reached as a step of its parent's body.

The line for a node in one of its parent's trays.

Types

answer()

@type answer() :: String.t() | :default

A callback's answer: its own line, or :default for the default line.

Callbacks

arm(node, default)

(optional)
@callback arm(node :: StatifierBlocks.Describe.Node.t(), default :: String.t()) ::
  answer()

The line for a node in one of its parent's side-by-side columns.

branch(edge, default)

(optional)
@callback branch(edge :: StatifierBlocks.Describe.Edge.t(), default :: String.t()) ::
  answer()

The line for a :branch edge.

entry(edge, default)

(optional)
@callback entry(edge :: StatifierBlocks.Describe.Edge.t(), default :: String.t()) ::
  answer()

The line for an :entry edge.

exit(edge, default)

(optional)
@callback exit(edge :: StatifierBlocks.Describe.Edge.t(), default :: String.t()) ::
  answer()

The line for an :exit edge.

interrupt(edge, default)

(optional)
@callback interrupt(edge :: StatifierBlocks.Describe.Edge.t(), default :: String.t()) ::
  answer()

The line for an :interrupt edge.

rail(node, default)

(optional)
@callback rail(node :: StatifierBlocks.Describe.Node.t(), default :: String.t()) ::
  answer()

The line for a node on one of its parent's rails.

sequence(edge, default)

(optional)
@callback sequence(edge :: StatifierBlocks.Describe.Edge.t(), default :: String.t()) ::
  answer()

The line for a :sequence edge.

step(node, default)

(optional)
@callback step(node :: StatifierBlocks.Describe.Node.t(), default :: String.t()) ::
  answer()

The line for a node reached as a step of its parent's body.

tray(node, default)

(optional)
@callback tray(node :: StatifierBlocks.Describe.Node.t(), default :: String.t()) ::
  answer()

The line for a node in one of its parent's trays.