PhiaUiDesign.Codegen.HeexEmitter (phia_ui v0.1.17)

Copy Markdown View Source

Converts a scene graph into a valid HEEx template string.

Walks the tree returned by Scene.to_tree/1 and emits properly indented HEEx markup. Each node type maps to a different output form:

  • :phia_component - <.button variant={:primary}>Label</.button>
  • :html_element - <div class="flex gap-4">...</div>
  • :text - plain text content
  • :frame - rendered as a <div> wrapper

Named slots are emitted as <:slot_name>content</:slot_name> inside the component tag. The special :inner_block / "inner_block" slot is rendered as direct text content (not wrapped in a slot tag).

Summary

Functions

Emit a complete HEEx string from an entire scene.

Emit HEEx for a single node (looked up by ID) and all its descendants.

Functions

emit(scene, opts \\ [])

@spec emit(
  reference(),
  keyword()
) :: String.t()

Emit a complete HEEx string from an entire scene.

Options

  • :indent - initial indentation level (default: 0)
  • :indent_size - number of spaces per indent level (default: 2)

Examples

scene = Scene.new()
{:ok, _} = Scene.insert_component(scene, :button, attrs: %{variant: :primary})
HeexEmitter.emit(scene)
#=> ~s(<.button variant={:primary} />)

emit_node(scene, node_id, opts \\ [])

@spec emit_node(reference(), String.t(), keyword()) :: String.t()

Emit HEEx for a single node (looked up by ID) and all its descendants.

Returns an empty string if the node is not found.

Options

Same as emit/2.