StarView.Template.Node (star_view v0.7.0)

Copy Markdown View Source

One node of a StarView.Template tree.

KindFieldsRendering
:textvalueTrusted static HTML source, emitted verbatim
:valuevalueHTML-escaped with Phoenix.HTML; a nested StarView.Template renders structurally
:elementtag, attrs, childrenA normal HTML element
:branchkey, childrenThe chosen branch; key identifies which one
:keyedchildren:fragment items, each with a unique key
:fragmentchildren, optional keyIts children
:componentvalueA native StarView.Template; legacy HEEx results are rejected

:text values and {:static, ...} attribute values are compiler output and must already be entity-escaped source. They are never escaped again.

Compiled branch/collection children may hold internal programs before materialization. StarView.Template.nodes/1 expands those into ordinary nodes.

Element meta

  • :void? - true for void elements such as <br>; they render no closing tag and must have no children.
  • :namespace - :svg or :mathml for foreign elements; defaults to HTML.
  • :browser_owned? - true when browser code (a Rocket host, an editor) manages the element's descendants. Diffs never target those descendants.

Other meta (dependencies, source location) is free-form and ignored by rendering. Do not store a conn in meta.

Attributes

  • {:static, name, raw_value, delimiter} - raw_value is entity-escaped source and delimiter is "\"" or "'". A nil value renders a bare boolean attribute.
  • {:dynamic, name, value} - escaped like HEEx name={value}: true renders a bare attribute, nil and false omit it, class accepts lists, and class/style are always emitted.
  • {:spread, list_or_map} - escaped like HEEx {@rest}.

Dynamic and spread names are validated before rendering. Names containing whitespace, quotes, <, >, /, =, & or backticks raise.

Summary

Functions

Builds a :branch node for the chosen branch key.

Builds a :component node.

Builds a :fragment node, optionally keyed for item identity.

Builds a :keyed node from :fragment items.

Builds a :text node from trusted, already-escaped HTML source.

Builds a :value node.

Types

attr()

@type attr() ::
  {:static, String.t(), String.t() | nil, String.t() | nil}
  | {:dynamic, String.t(), term()}
  | {:spread, keyword() | map()}

child()

@type child() :: t() | StarView.Template.Program.t()

kind()

@type kind() :: :text | :value | :element | :branch | :keyed | :fragment | :component

t()

@type t() :: %StarView.Template.Node{
  attrs: [attr()],
  children: [child()],
  key: term(),
  kind: kind(),
  meta: map(),
  tag: String.t() | nil,
  value: term()
}

Functions

branch(key, children, meta \\ %{})

@spec branch(term(), [child()], map()) :: t()

Builds a :branch node for the chosen branch key.

component(value, meta \\ %{})

@spec component(StarView.Template.t(), map()) :: t()

Builds a :component node.

element(tag, attrs \\ [], children \\ [], meta \\ %{})

@spec element(String.t(), [attr()], [child()], map()) :: t()

Builds an :element node.

fragment(children, key \\ nil, meta \\ %{})

@spec fragment([child()], term(), map()) :: t()

Builds a :fragment node, optionally keyed for item identity.

keyed(items, meta \\ %{})

@spec keyed([child()], map()) :: t()

Builds a :keyed node from :fragment items.

text(html)

@spec text(String.t()) :: t()

Builds a :text node from trusted, already-escaped HTML source.

value(value, meta \\ %{})

@spec value(term(), map()) :: t()

Builds a :value node.