Events: route imports now point to specific sub-modules (entries, tickets, slots) instead of all going through renders.py. Merged layouts into helpers.py. __init__.py now 20 lines. SX Docs: moved dispatchers from helpers.py into essays.py, cleaned up __init__.py to 24 lines. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
137 lines
4.7 KiB
Python
137 lines
4.7 KiB
Python
"""Public partials and page helper registration for sx docs."""
|
|
from __future__ import annotations
|
|
|
|
from .essays import (
|
|
_docs_content_sx, _reference_content_sx, _protocol_content_sx,
|
|
_examples_content_sx, _essay_content_sx,
|
|
_reference_index_sx, _reference_attr_detail_sx,
|
|
)
|
|
from .utils import _docs_nav_sx, _reference_nav_sx, _protocols_nav_sx, _examples_nav_sx, _essays_nav_sx
|
|
from content.highlight import highlight
|
|
|
|
|
|
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,
|
|
})
|