server.alpine

Page actions AI-ready formats and sharing
Open LLM text
Share with AI
Ask Claude Ask ChatGPT Ask Gemini Ask Copilot

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…

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.

server.alpine

Name Type Default Description
type
qualified_name
element_type
description
source_file
line_number
is_autodoc
autodoc_element
_autodoc_template
_autodoc_url_path
_autodoc_page_type
title
doc_content_hash

Symbols on this page

safe_data_helper
function
def safe_data_helper(nonce: str = '') -> str

Build the AlpinesafeData helper inline <script>.

When nonce is non-empty the<script> carries a nonce="..." attribute so it survives a nonce-based CSP that no longer ships 'unsafe-inline'.

Parameters

Name Type Default Description
nonce str ''
plugin_snippet
function
def plugin_snippet(version: str) -> str

Build Alpine plugin script tags pinned to the core version.

Parameters

Name Type Default Description
version str
alpine_json_config
function
def alpine_json_config(dom_id: str, data: Any, *, nonce: str = '') -> 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 Default 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=str`` for non-JSON-serializable types.
nonce str ''
alpine_snippet
function
def alpine_snippet(version: str, csp: bool = False, *, nonce: str = '') -> 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 Default Description
version str Alpine version (e.g. "3.15.8").
csp bool False If True, use the ``@alpinejs/csp`` browser CDN build (also explicit ``dist/cdn.min.js``; that package's main is CJS too).
nonce str ''

View source · /home/runner/work/chirp/chirp/site/../src/chirp/server/alpine.py:1