Macaw.Frame.Preset behaviour (macaw_frame v0.1.0)

Copy Markdown View Source

Presets as registered fragments (spec/02 §14), replacing visualize's Visualize.Chart.Presets and its function components: a preset is a stored composite or design fragment with its variables declared as parameters, found by name and placed as any fragment is. Nothing is a function component.

A preset is a module implementing this behavior. The registry is explicit and default closed (registry/1), built from the packages a host lists, each package's __members__/0 read for the modules implementing it; a name two presets claim is a fault of the registry, and every preset's fragment is checked with its kind's per-kind validity (Macaw.Frame.Document.validate/2), each fault under the preset's name.

A preset is used by its fragment (fetch/2): a host stacks it under a design's own layers, binds its variables at a site (Macaw.Layers.Use with vars:), or copies it into its store. It is never referenced by name from inside a document. visualize's ten presets become registered presets with the catalog's designs (spec/13); none is registered in macaw_frame's package until then.

iex> Macaw.Frame.Preset.registry([])
{:ok, %{}}
iex> Macaw.Frame.Preset.fetch(%{}, "bar_chart")
:error

Summary

Types

A registry of presets by name.

Callbacks

What it draws, for a person and a catalog.

The fragment: a composite, or a design, with its variables and slots declared.

The preset's name, unique in a registry ("line_chart").

Functions

A preset's fragment by name, read by spelling: {:ok, fragment} or :error.

The registry's preset names, sorted.

Whether a module implements every callback of the behavior.

The registry of the presets the packages hold: {:ok, %{name => module}}, or every fault at once: a module that is no package {[:packages, i], :not_a_package}; a name two presets claim {[:presets, name], {:named_twice, module, other}}; a preset's fragment that no kind fits {[:presets, name], {:type, :fragment}}, and its per-kind validity's faults under [:presets, name | path].

Types

registry()

@type registry() :: %{required(String.t()) => module()}

A registry of presets by name.

Callbacks

doc()

@callback doc() :: String.t()

What it draws, for a person and a catalog.

fragment()

@callback fragment() :: map()

The fragment: a composite, or a design, with its variables and slots declared.

name()

@callback name() :: String.t()

The preset's name, unique in a registry ("line_chart").

Functions

fetch(registry, name)

@spec fetch(term(), term()) :: {:ok, map()} | :error

A preset's fragment by name, read by spelling: {:ok, fragment} or :error.

names(registry)

@spec names(term()) :: [String.t()]

The registry's preset names, sorted.

preset?(module)

@spec preset?(term()) :: boolean()

Whether a module implements every callback of the behavior.

registry(packages)

@spec registry(term()) :: {:ok, registry()} | {:error, [Macaw.Base.Fault.t(), ...]}

The registry of the presets the packages hold: {:ok, %{name => module}}, or every fault at once: a module that is no package {[:packages, i], :not_a_package}; a name two presets claim {[:presets, name], {:named_twice, module, other}}; a preset's fragment that no kind fits {[:presets, name], {:type, :fragment}}, and its per-kind validity's faults under [:presets, name | path].