OpenFresco.Substitute (open_fresco v0.1.0)

Copy Markdown View Source

Inline token substitution — the templating model shared with phoenix_kit_og, ported for byte-compatibility so stored templates migrate without rewriting bindings.

Two bracket styles, both \w+ names, both resolved from a single values map:

  • {{slot}} — a template-local slot, wired to a concrete value per render (the post title, hero src, …). Listed by slots/1 for a wiring UI, with a :text / :image type inferred from where it appears.
  • [[global]] — a global that resolves from ambient context (site host, page URL, locale). Same substitution pass, different bracket; not listed as a slot.

Callers merge globals + wired slot values into one map (see OpenFresco.render_svg/3's :globals option). Unknown names pass through unchanged so an unwired {{Title}} stays visible in the output as a "needs wiring" signal — matching og.

Summary

Functions

Substitute {{slot}} and [[global]] tokens in text from values (string keys). Unknown names pass through unchanged. A nil text is "".

The {{slot}} names used across a scene, in first-appearance order, each tagged with the :text / :image type inferred from the field it appears in. Feeds a wiring UI (the phoenix_kit_og Assignments equivalent).

Whether a substituted string still carries an unresolved {{slot}} token (used by the image path to decide between drawing the resolved src and the neutral stand-in).

Functions

apply(text, values)

@spec apply(String.t() | %{placeholder: String.t()} | nil, map()) :: String.t()

Substitute {{slot}} and [[global]] tokens in text from values (string keys). Unknown names pass through unchanged. A nil text is "".

A whole-value placeholder (%{placeholder: "k"}) is accepted as a degenerate case — treated as the string "{{k}}".

slots(scene)

@spec slots(OpenFresco.Scene.t()) :: [%{name: String.t(), type: :text | :image}]

The {{slot}} names used across a scene, in first-appearance order, each tagged with the :text / :image type inferred from the field it appears in. Feeds a wiring UI (the phoenix_kit_og Assignments equivalent).

unresolved?(text)

@spec unresolved?(String.t()) :: boolean()

Whether a substituted string still carries an unresolved {{slot}} token (used by the image path to decide between drawing the resolved src and the neutral stand-in).