Module

server.alpine

Alpine.js script injection — single-authority Alpine for all Chirp apps.

Chirp is the sole injector of Alpine.js.use_chirp_ui()auto-enables alpine=True, so chirp-ui's app_shell_layout.htmldoes not ship its own Alpine scripts.

Injects before</body> via AlpineInject (dedup-aware HTMLInject subclass) whenAppConfig(alpine=True). Includes:

  • All plugins (Mask, Intersect, Focus)
  • Store init (modals, trays) for chirp-ui components
  • Alpine.safeData(name, factory) helper — htmx-safe Alpine.data() that works on full page loads and boosted navigation swaps.

Usesdeferso Alpine runs after DOM parsing; Alpine 3 auto-discovers elements including those swapped by htmx.

Functions

plugin_snippet 1 str
Build Alpine plugin script tags pinned to the core version.
def plugin_snippet(version: str) -> str
Parameters
Name Type Description
version str
Returns
str
alpine_json_config 2 Markup
Emit a ```` tag for Alpine component config. Provides a safe bridge for passin…
def alpine_json_config(dom_id: str, data: Any) -> Markup

Emit a<script type="application/json">tag for Alpine component config.

Provides a safe bridge for passing server-side data to client-side Alpine components without HTML attribute quoting issues. Registered as a template global whenAppConfig(alpine=True).

Parameters
Name Type Description
dom_id str

id attribute for the script tag. Used to locate and parse the config via document.getElementById(...).textContent.

data Any

Python value to serialize as JSON. Uses :func:json.dumps with default=strfor non-JSON-serializable types.

Returns
Markup
alpine_snippet 2 str
Build the full Alpine.js injection block. Includes plugins (Mask, Intersect, F…
def alpine_snippet(version: str, csp: bool = False) -> str

Build the full Alpine.js injection block.

Includes plugins (Mask, Intersect, Focus) pinned to the same version as the Alpine core script, thesafeDatahelper with chirp-ui store init, and the Alpine.js core script.

The script URL must include/dist/cdn.min.js. A bare alpinejs@version path on jsdelivr resolves topackage.json main (dist/module.cjs.js), which is CommonJS and throwsReferenceError: module is not definedin the browser when loaded as a classic script.

Parameters
Name Type Description
version str

Alpine version (e.g. "3.15.8").

csp bool

If True, use the@alpinejs/csp browser CDN build (also explicit dist/cdn.min.js; that package's main is CJS too).

Default:False
Returns
str