Lavash.Template.AttrHelpers (Lavash v0.4.0-rc.5)

Copy Markdown View Source

Small helpers for manipulating the attribute list shape that Lavash.TagEngine produces.

Attributes come as tuples of {name, value, meta} where value is {:string, content, meta} | {:expr, code, meta} | nil. Spread attrs use {:root, value, meta} and have no string name — the helpers below treat those as pass-through (they only check named attrs).

Why a separate module

Extracted from the original 800-line Lavash.Template.TokenTransformer so the new single-purpose sub-transformers can share the helpers without anyone owning a dependency on the old monolith.

Summary

Functions

Appends {name, value, meta} to attrs unless an attribute by that name already exists. Used to inject data-lavash-* attrs without overwriting any the user wrote by hand.

Returns the value tuple for the named attribute, or nil if missing.

Returns true if any non-:root attribute matches name.

Removes any attribute matching name. Spread attrs are kept.

Functions

add_attr_if_missing(attrs, name, value)

Appends {name, value, meta} to attrs unless an attribute by that name already exists. Used to inject data-lavash-* attrs without overwriting any the user wrote by hand.

value can be {:string, "foo"} (gets default meta wrapped) or {:expr, "@foo"} (gets passed through with meta).

get_attr_value(attrs, name)

Returns the value tuple for the named attribute, or nil if missing.

has_attr?(attrs, name)

Returns true if any non-:root attribute matches name.

reject_attr(attrs, name)

Removes any attribute matching name. Spread attrs are kept.