# `Macaw.Template.Layer`
[🔗](https://github.com/dcoai/macaw/blob/v0.6.0/lib/macaw/template/layer.ex#L1)

A layer on a template (spec/06 §2.3): `%Macaw.Template.Layer{name, on, regions, order,
layout, params, disclosures, mask}`, a fragment of a template holding only what it gives.

  * `name`, its name, and `on`, the template it stacks on, both required;
  * `regions`, what it changes of each region by name, a region's keys but its name; a
    region the template lacks is added;
  * `order`, the regions' order restated, and `layout`, the layout restated, or `nil`;
  * `params`, values of the template's params by name;
  * `disclosures`, `:open` or `:default`, or `nil`;
  * `mask`, the paths it drops from below before it stacks, or `:all`.

A layer is written in code with `use Macaw.Template` and `layer/2`, or built from its
keys by `new/1`. `Macaw.Template.stack/2` stacks it.

    iex> {:ok, layer} = Macaw.Template.Layer.new(name: :full_width, on: :site, regions: [sidebar: [hidden: true]])
    iex> {layer.on, layer.regions}
    {"site", %{"sidebar" => %{hidden: true}}}

# `path`

```elixir
@type path() :: [atom() | String.t(), ...]
```

# `t`

```elixir
@type t() :: %Macaw.Template.Layer{
  disclosures: :default | :open | nil,
  layout: :stack | {:areas, map()} | nil,
  mask: [path()] | :all,
  name: String.t(),
  on: String.t(),
  order: [String.t()] | nil,
  params: %{required(String.t()) =&gt; term()},
  regions: %{required(String.t()) =&gt; map()}
}
```

# `mask_path`

```elixir
@spec mask_path(term()) :: {:ok, path()} | :error
```

Whether a term is a mask's path, read with its names spelled: `{:ok, path}` or `:error`.
The paths are `[:regions]`, `[:regions, region]`, `[:regions, region, key]`,
`[:params]`, `[:params, param]`, `[:order]`, `[:layout]` and `[:disclosures]`.

    iex> Macaw.Template.Layer.mask_path([:regions, :sidebar, :content])
    {:ok, [:regions, "sidebar", :content]}
    iex> Macaw.Template.Layer.mask_path([:regions, :sidebar, :name])
    :error

# `new`

```elixir
@spec new(map() | keyword()) :: {:ok, t()} | {:error, [Macaw.Base.Fault.t(), ...]}
```

A layer from a keyword list or a map with atom keys: `{:ok, layer}` or every fault at
once by path. `name` and `on` are `:required` or `{:type, :name}`; a region's key is
judged as `Macaw.Region.new/1` judges it, at `[:regions, region, key]`, its `name`
`:unknown_key`, and a region name that isn't one `{:type, :name}` at `[:regions,
region]`; an `order` that isn't a list of names `{:type, :order}`; a layout as a
template's; a param name that isn't one `{:type, :name}`; `disclosures`
`{:enum, [:default, :open]}`; a mask's path that isn't one of a template's
`{:type, :mask}` at `[:mask, i]`; another key `:unknown_key`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
