Events: 3861 → 21 lines, split into 8 sub-modules (renders, helpers, layouts, calendar, entries, slots, tickets, utils). Updated 16 bp routes. SX Docs: 3224 → 27 lines, split into 5 sub-modules (renders, utils, essays, helpers, layouts). Updated 37 import sites in bp/pages/routes.py. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
240 lines
9.3 KiB
Python
240 lines
9.3 KiB
Python
"""Dispatcher functions, public partials, and page helper registration for sx docs."""
|
|
from __future__ import annotations
|
|
|
|
from .essays import (
|
|
_docs_introduction_sx, _docs_getting_started_sx, _docs_components_sx,
|
|
_docs_evaluator_sx, _docs_primitives_sx, _docs_css_sx, _docs_server_rendering_sx,
|
|
_reference_index_sx, _reference_attr_detail_sx, _reference_attrs_sx,
|
|
_reference_headers_sx, _reference_events_sx, _reference_js_api_sx,
|
|
_protocol_wire_format_sx, _protocol_fragments_sx, _protocol_resolver_io_sx,
|
|
_protocol_internal_services_sx, _protocol_activitypub_sx, _protocol_future_sx,
|
|
_example_click_to_load_sx, _example_form_submission_sx, _example_polling_sx,
|
|
_example_delete_row_sx, _example_inline_edit_sx, _example_oob_swaps_sx,
|
|
_example_lazy_loading_sx, _example_infinite_scroll_sx, _example_progress_bar_sx,
|
|
_example_active_search_sx, _example_inline_validation_sx, _example_value_select_sx,
|
|
_example_reset_on_submit_sx, _example_edit_row_sx, _example_bulk_update_sx,
|
|
_example_swap_positions_sx, _example_select_filter_sx, _example_tabs_sx,
|
|
_example_animations_sx, _example_dialogs_sx, _example_keyboard_shortcuts_sx,
|
|
_example_put_patch_sx, _example_json_encoding_sx, _example_vals_and_headers_sx,
|
|
_example_loading_states_sx, _example_sync_replace_sx, _example_retry_sx,
|
|
_essay_sx_sucks, _essay_why_sexps, _essay_htmx_react_hybrid,
|
|
_essay_on_demand_css, _essay_client_reactivity, _essay_sx_native,
|
|
_essay_sx_manifesto, _essay_tail_call_optimization, _essay_continuations,
|
|
)
|
|
from .utils import _docs_nav_sx, _reference_nav_sx, _protocols_nav_sx, _examples_nav_sx, _essays_nav_sx
|
|
from content.highlight import highlight
|
|
|
|
async def _docs_content_sx(slug: str) -> str:
|
|
"""Route to the right docs content builder."""
|
|
import inspect
|
|
builders = {
|
|
"introduction": _docs_introduction_sx,
|
|
"getting-started": _docs_getting_started_sx,
|
|
"components": _docs_components_sx,
|
|
"evaluator": _docs_evaluator_sx,
|
|
"primitives": _docs_primitives_sx,
|
|
"css": _docs_css_sx,
|
|
"server-rendering": _docs_server_rendering_sx,
|
|
}
|
|
builder = builders.get(slug, _docs_introduction_sx)
|
|
result = builder()
|
|
return await result if inspect.isawaitable(result) else result
|
|
|
|
|
|
async def _reference_content_sx(slug: str) -> str:
|
|
import inspect
|
|
builders = {
|
|
"attributes": _reference_attrs_sx,
|
|
"headers": _reference_headers_sx,
|
|
"events": _reference_events_sx,
|
|
"js-api": _reference_js_api_sx,
|
|
}
|
|
result = builders.get(slug or "", _reference_attrs_sx)()
|
|
return await result if inspect.isawaitable(result) else result
|
|
|
|
|
|
def _protocol_content_sx(slug: str) -> str:
|
|
builders = {
|
|
"wire-format": _protocol_wire_format_sx,
|
|
"fragments": _protocol_fragments_sx,
|
|
"resolver-io": _protocol_resolver_io_sx,
|
|
"internal-services": _protocol_internal_services_sx,
|
|
"activitypub": _protocol_activitypub_sx,
|
|
"future": _protocol_future_sx,
|
|
}
|
|
return builders.get(slug, _protocol_wire_format_sx)()
|
|
|
|
|
|
def _examples_content_sx(slug: str) -> str:
|
|
builders = {
|
|
"click-to-load": _example_click_to_load_sx,
|
|
"form-submission": _example_form_submission_sx,
|
|
"polling": _example_polling_sx,
|
|
"delete-row": _example_delete_row_sx,
|
|
"inline-edit": _example_inline_edit_sx,
|
|
"oob-swaps": _example_oob_swaps_sx,
|
|
"lazy-loading": _example_lazy_loading_sx,
|
|
"infinite-scroll": _example_infinite_scroll_sx,
|
|
"progress-bar": _example_progress_bar_sx,
|
|
"active-search": _example_active_search_sx,
|
|
"inline-validation": _example_inline_validation_sx,
|
|
"value-select": _example_value_select_sx,
|
|
"reset-on-submit": _example_reset_on_submit_sx,
|
|
"edit-row": _example_edit_row_sx,
|
|
"bulk-update": _example_bulk_update_sx,
|
|
"swap-positions": _example_swap_positions_sx,
|
|
"select-filter": _example_select_filter_sx,
|
|
"tabs": _example_tabs_sx,
|
|
"animations": _example_animations_sx,
|
|
"dialogs": _example_dialogs_sx,
|
|
"keyboard-shortcuts": _example_keyboard_shortcuts_sx,
|
|
"put-patch": _example_put_patch_sx,
|
|
"json-encoding": _example_json_encoding_sx,
|
|
"vals-and-headers": _example_vals_and_headers_sx,
|
|
"loading-states": _example_loading_states_sx,
|
|
"sync-replace": _example_sync_replace_sx,
|
|
"retry": _example_retry_sx,
|
|
}
|
|
return builders.get(slug, _example_click_to_load_sx)()
|
|
|
|
|
|
def _essay_content_sx(slug: str) -> str:
|
|
builders = {
|
|
"sx-sucks": _essay_sx_sucks,
|
|
"why-sexps": _essay_why_sexps,
|
|
"htmx-react-hybrid": _essay_htmx_react_hybrid,
|
|
"on-demand-css": _essay_on_demand_css,
|
|
"client-reactivity": _essay_client_reactivity,
|
|
"sx-native": _essay_sx_native,
|
|
"sx-manifesto": _essay_sx_manifesto,
|
|
"tail-call-optimization": _essay_tail_call_optimization,
|
|
"continuations": _essay_continuations,
|
|
}
|
|
return builders.get(slug, _essay_sx_sucks)()
|
|
|
|
|
|
def home_content_sx() -> str:
|
|
"""Home page content as sx wire format."""
|
|
hero_code = highlight('(div :class "p-4 bg-white rounded shadow"\n'
|
|
' (h1 :class "text-2xl font-bold" "Hello")\n'
|
|
' (button :sx-get "/api/data"\n'
|
|
' :sx-target "#result"\n'
|
|
' "Load data"))', "lisp")
|
|
return (
|
|
f'(section :id "main-panel"'
|
|
f' :class "flex-1 md:h-full md:min-h-0 overflow-y-auto overscroll-contain js-grid-viewport"'
|
|
f' (div :id "main-content"'
|
|
f' (~sx-hero {hero_code})'
|
|
f' (~sx-philosophy)'
|
|
f' (~sx-how-it-works)'
|
|
f' (~sx-credits)))'
|
|
)
|
|
|
|
|
|
async def docs_content_partial_sx(slug: str) -> str:
|
|
"""Docs content as sx wire format."""
|
|
inner = await _docs_content_sx(slug)
|
|
return (
|
|
f'(section :id "main-panel"'
|
|
f' :class "flex-1 md:h-full md:min-h-0 overflow-y-auto overscroll-contain js-grid-viewport"'
|
|
f' {inner})'
|
|
)
|
|
|
|
|
|
async def reference_content_partial_sx(slug: str) -> str:
|
|
inner = await _reference_content_sx(slug)
|
|
return (
|
|
f'(section :id "main-panel"'
|
|
f' :class "flex-1 md:h-full md:min-h-0 overflow-y-auto overscroll-contain js-grid-viewport"'
|
|
f' {inner})'
|
|
)
|
|
|
|
|
|
async def protocol_content_partial_sx(slug: str) -> str:
|
|
inner = await _protocol_content_sx(slug)
|
|
return (
|
|
f'(section :id "main-panel"'
|
|
f' :class "flex-1 md:h-full md:min-h-0 overflow-y-auto overscroll-contain js-grid-viewport"'
|
|
f' {inner})'
|
|
)
|
|
|
|
|
|
async def examples_content_partial_sx(slug: str) -> str:
|
|
inner = await _examples_content_sx(slug)
|
|
return (
|
|
f'(section :id "main-panel"'
|
|
f' :class "flex-1 md:h-full md:min-h-0 overflow-y-auto overscroll-contain js-grid-viewport"'
|
|
f' {inner})'
|
|
)
|
|
|
|
|
|
async def essay_content_partial_sx(slug: str) -> str:
|
|
inner = await _essay_content_sx(slug)
|
|
return (
|
|
f'(section :id "main-panel"'
|
|
f' :class "flex-1 md:h-full md:min-h-0 overflow-y-auto overscroll-contain js-grid-viewport"'
|
|
f' {inner})'
|
|
)
|
|
|
|
|
|
def _register_sx_helpers() -> None:
|
|
"""Register Python content builder functions as page helpers."""
|
|
from shared.sx.pages import register_page_helpers
|
|
from content.highlight import highlight as _highlight
|
|
from content.pages import (
|
|
DOCS_NAV, REFERENCE_NAV, PROTOCOLS_NAV,
|
|
EXAMPLES_NAV, ESSAYS_NAV,
|
|
)
|
|
|
|
def _find_current(nav_list, slug, match_fn=None):
|
|
"""Find the current nav label for a slug."""
|
|
if match_fn:
|
|
return match_fn(nav_list, slug)
|
|
for label, href in nav_list:
|
|
if href.endswith(slug):
|
|
return label
|
|
return None
|
|
|
|
def _home_content():
|
|
"""Build home page content (uses highlight for hero code block)."""
|
|
hero_code = _highlight(
|
|
'(div :class "p-4 bg-white rounded shadow"\n'
|
|
' (h1 :class "text-2xl font-bold" "Hello")\n'
|
|
' (button :sx-get "/api/data"\n'
|
|
' :sx-target "#result"\n'
|
|
' "Load data"))', "lisp")
|
|
return (
|
|
f'(div :id "main-content"'
|
|
f' (~sx-hero {hero_code})'
|
|
f' (~sx-philosophy)'
|
|
f' (~sx-how-it-works)'
|
|
f' (~sx-credits))'
|
|
)
|
|
|
|
register_page_helpers("sx", {
|
|
# Content builders
|
|
"home-content": _home_content,
|
|
"docs-content": _docs_content_sx,
|
|
"reference-content": _reference_content_sx,
|
|
"reference-index-content": _reference_index_sx,
|
|
"reference-attr-detail": _reference_attr_detail_sx,
|
|
"protocol-content": _protocol_content_sx,
|
|
"examples-content": _examples_content_sx,
|
|
"essay-content": _essay_content_sx,
|
|
"highlight": _highlight,
|
|
# Nav builders
|
|
"docs-nav": _docs_nav_sx,
|
|
"reference-nav": _reference_nav_sx,
|
|
"protocols-nav": _protocols_nav_sx,
|
|
"examples-nav": _examples_nav_sx,
|
|
"essays-nav": _essays_nav_sx,
|
|
# Nav data (for current label lookup)
|
|
"DOCS_NAV": DOCS_NAV,
|
|
"REFERENCE_NAV": REFERENCE_NAV,
|
|
"PROTOCOLS_NAV": PROTOCOLS_NAV,
|
|
"EXAMPLES_NAV": EXAMPLES_NAV,
|
|
"ESSAYS_NAV": ESSAYS_NAV,
|
|
# Utility
|
|
"find-current": _find_current,
|
|
})
|