Major architectural change: page function dispatch and handler execution
now go through the OCaml kernel instead of the Python bootstrapped evaluator.
OCaml integration:
- Page dispatch: bridge.eval() evaluates SX URL expressions (geography, marshes, etc.)
- Handler aser: bridge.aser() serializes handler responses as SX wire format
- _ensure_components loads all .sx files into OCaml kernel (spec, web adapter, handlers)
- defhandler/defpage registered as no-op special forms so handler files load
- helper IO primitive dispatches to Python page helpers + IO handlers
- ok-raw response format for SX wire format (no double-escaping)
- Natural list serialization in eval (no (list ...) wrapper)
- Clean pipe: _read_until_ok always sends io-response on error
SX adapter (aser):
- scope-emit!/scope-peek aliases to avoid CEK special form conflict
- aser-fragment/aser-call: strings starting with "(" pass through unserialized
- Registered cond-scheme?, is-else-clause?, primitive?, get-primitive in kernel
- random-int, parse-int as kernel primitives; json-encode, into via IO bridge
Handler migration:
- All IO calls converted to (helper "name" args...) pattern
- request-arg, request-form, state-get, state-set!, now, component-source etc.
- Fixed bare (effect ...) in island bodies leaking disposer functions as text
- Fixed lower-case → lower, ~search-results → ~examples/search-results
Reactive islands:
- sx-hydrate-islands called after client-side navigation swap
- force-dispose-islands-in for outerHTML swaps (clears hydration markers)
- clear-processed! platform primitive for re-hydration
Content restructuring:
- Design, event bridge, named stores, phase 2 consolidated into reactive overview
- Marshes split into overview + 5 example sub-pages
- Nav links use sx-get/sx-target for client-side navigation
Playwright test suite (sx/tests/test_demos.py):
- 83 tests covering hypermedia demos, reactive islands, marshes, spec explorer
- Server-side rendering, handler interactions, island hydration, navigation
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
37 lines
1.7 KiB
Python
37 lines
1.7 KiB
Python
"""SX docs defpage setup — registers layouts, page helpers, and loads .sx pages."""
|
|
from __future__ import annotations
|
|
|
|
|
|
def setup_sx_pages() -> None:
|
|
"""Register sx-specific layouts, page helpers, and load page definitions."""
|
|
from .layouts import _register_sx_layouts
|
|
from .helpers import _register_sx_helpers
|
|
_register_sx_layouts()
|
|
_register_sx_helpers()
|
|
_load_sx_page_files()
|
|
|
|
|
|
def _load_sx_page_files() -> None:
|
|
"""Load defpage definitions from sx/sxc/pages/*.sx."""
|
|
import os
|
|
from shared.sx.pages import load_page_dir, get_page_helpers
|
|
from shared.sx.jinja_bridge import load_sx_dir, watch_sx_dir, load_service_components
|
|
_sxc_dir = os.path.dirname(os.path.dirname(__file__)) # sx/sxc/
|
|
service_root = os.path.dirname(_sxc_dir) # sx/
|
|
load_service_components(service_root, service_name="sx")
|
|
load_sx_dir(_sxc_dir)
|
|
watch_sx_dir(_sxc_dir)
|
|
# Register page helpers as primitives so the CEK machine can find them
|
|
# during nested async component expansion (e.g. highlight inside ~docs/code
|
|
# inside a plan component inside ~layouts/doc). Without this, the env_merge
|
|
# chain loses page helpers because component closures don't capture them.
|
|
from shared.sx.ref.sx_ref import PRIMITIVES
|
|
helpers = get_page_helpers("sx")
|
|
for name, fn in helpers.items():
|
|
PRIMITIVES[name] = fn
|
|
|
|
# helper is registered as an IO primitive in primitives_io.py,
|
|
# intercepted by async_eval before hitting the CEK machine.
|
|
import logging; logging.getLogger("sx.pages").info("Injected %d page helpers as primitives: %s", len(helpers), list(helpers.keys())[:5])
|
|
load_page_dir(os.path.dirname(__file__), "sx")
|