PhoenixKitOG.Slots (PhoenixKitOG v0.1.1)

Copy Markdown View Source

Scans a canvas for {{slot}} references — the abstract, template- local names that get wired to concrete module variables at assignment time.

Also handles [[name]] "global" references — these resolve automatically from the OG module's own settings/context (site host, page URL, etc.) and never appear in the slots panel or need wiring. Same substitution pass, different bracket.

Syntax matches the workspace convention (phoenix_kit_ai.Prompt, publishing's translation module): \w+ names, inline interpolation OK anywhere text or an image src is accepted.

Slot type inference

Slots pick up a type from where they appear:

  • text/stamp element content, background color → :text
  • image element src:image

A slot referenced from multiple element kinds keeps whichever type came first. Wiring at assignment time filters module variables by type so an :image slot only shows image-typed vars in its dropdown.

Summary

Functions

Returns unique [[global]] names referenced in a string.

Substitutes both {{name}} (wired slot) and [[name]] (global) references from the values map. Unknown names pass through unchanged so the raw token stays visible — matches the workspace convention.

Returns unique slots used in the canvas, in first-appearance order.

Types

t()

@type t() :: %{name: String.t(), type: :text | :image}

Functions

globals_used(text)

@spec globals_used(String.t() | nil) :: [String.t()]

Returns unique [[global]] names referenced in a string.

substitute(text, values)

@spec substitute(String.t() | nil, %{optional(String.t()) => String.t()}) ::
  String.t()

Substitutes both {{name}} (wired slot) and [[name]] (global) references from the values map. Unknown names pass through unchanged so the raw token stays visible — matches the workspace convention.

Callers merge globals + wired slot values into a single map before calling; both bracket styles read the same map, and the distinction matters only for Slots.used/1 (which lists slots for the wiring UI and only picks up {{...}}).

used(canvas)

@spec used(map()) :: [t()]

Returns unique slots used in the canvas, in first-appearance order.