Macaw.Frame.Document.Validator (macaw_frame v0.1.0)

Copy Markdown View Source

Every fault of a frame document, by path (spec/02 §10).

validate/2 answers :ok or {:error, faults} with every fault, each {path, reason} (Macaw.Base.Fault), ordered by path. The path runs from the design to the value: [:layers, 1, :channels, "y"], [:styles, "series", :stroke]. A key the type does not know stays its string.

The value is judged in its canonical shape (Macaw.Frame.Document.Migration.canonical/1): names as strings, so an atom given in Elixir is read by its spelling and every path names a design's names as the map form does. For every node, in order: unknown keys; required keys; the type of every present value, recursing; enumerations; references (a scale against its frame's scales, a style against styles and the palette, a slot, a variable, a field, a paint, a theme slot); then what a node's keys owe each other.

Options: profile: (:roles, or :open to allow literal colors, §1.6), layers: and models: (the registries a Frame passes, %{name => module}; without one a kind's or a model's name is not looked up), generators: (the host's generator modules, handed to Macaw.Draw.Generators.registry/1, or a registry it built; its faults are the read's, at [:generators | path]; without it a generator's name is not looked up, §3.13).

iex> Macaw.Frame.Document.Validator.validate(%{})
{:error, [{[:frames], :required}]}
iex> Macaw.Frame.Document.Validator.validate(%{frames: %{main: %{kind: "cartesian"}}})
:ok

Summary

Functions

:ok, or every fault of the design ordered by path; opts as the module says.

:ok, or every fault of a fragment read as a kind of spec/02 §16.1, per-kind validity: a design is validated whole; any other kind is the body under its singular key (%{style: node}, %{layer: node}, %{frames: %{name => node}}), walked with that kind's schema and nothing around it, so no key is required and no reference is looked up. A fragment whose shape is not the kind's is {:type, {:node, kind}} at [].

Functions

validate(design, opts \\ [])

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

:ok, or every fault of the design ordered by path; opts as the module says.

validate_kind(fragment, kind, opts \\ [])

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

:ok, or every fault of a fragment read as a kind of spec/02 §16.1, per-kind validity: a design is validated whole; any other kind is the body under its singular key (%{style: node}, %{layer: node}, %{frames: %{name => node}}), walked with that kind's schema and nothing around it, so no key is required and no reference is looked up. A fragment whose shape is not the kind's is {:type, {:node, kind}} at [].

iex> Macaw.Frame.Document.Validator.validate_kind(%{style: %{extends: "elsewhere"}}, :style)
:ok