AttrEngine.Cascade (attr_engine v0.2.1)

Copy Markdown View Source

4-layer config cascade resolution.

Resolves the effective configuration for each attribute in a block by merging configs from all layers:

  1. Attribute — structural defaults (data_config, ui_config)
  2. ASA — semantic overrides for this set
  3. ASD — per-instance overrides
  4. Runtime — transforms, enrichments

Usage

# Get resolved attribute metadata for a block type
attrs_meta = AttrEngine.Cascade.resolve_attrs_meta(block_type_handle)

# Apply ASD ui_config overrides on top
final_meta = AttrEngine.Cascade.apply_asd_overrides(attrs_meta, asd_ui_config)

# Get the full rendering context (data + ui keys flattened)
context = AttrEngine.Cascade.build_context(attrs_meta, data, locale)

Summary

Functions

Applies ASD (per-instance) ui_config overrides on top of resolved attrs_meta.

Builds a flat rendering context from resolved attrs_meta and data.

Resolves the full attribute metadata for a block type, including cascaded configs.

Functions

apply_asd_overrides(attrs_meta, asd_ui)

@spec apply_asd_overrides([map()], map() | nil) :: [map()]

Applies ASD (per-instance) ui_config overrides on top of resolved attrs_meta.

asd_ui is keyed by attribute handle:

%{"title" => %{"classes" => "text-center", "append" => true}}

If "append" is true, string values are concatenated. Otherwise, replaced.

build_context(attrs_meta, data, set_ui_config \\ %{})

@spec build_context([map()], map(), map()) :: map()

Builds a flat rendering context from resolved attrs_meta and data.

Returns a map with:

  • Data values keyed by handle
  • UI keys prefixed: {handle}_tag, {handle}_class, etc.
  • Block-level UI keys from the AttributeSet: block_tag, block_class, etc.

resolve_attrs_meta(attribute_set_id)

@spec resolve_attrs_meta(integer()) :: [map()]

Resolves the full attribute metadata for a block type, including cascaded configs.

Returns a list of maps:

[
  %{
    handle: "title",
    type: :string,
    localized: true,
    data_config: %{...},   # merged: Attribute → ASA
    ui_config: %{...}      # merged: Attribute → ASA
  },
  ...
]

Ordered by ASA.sort.