Migrate ~2,500 lines of SX markup from Python string concatenation in essays.py to proper .sx defcomp definitions: - docs-content.sx: 8 defcomps for docs pages (intro, getting-started, components, evaluator, primitives, css, server-rendering, home) - protocols.sx: 6 defcomps for protocol documentation pages - essays.sx: 9 essay defcomps (pure content, no params) - examples.sx: template defcomp receiving data values, calls highlight internally — Python passes raw code strings, never SX - reference.sx: 6 defcomps for data-driven reference pages essays.py reduced from 2,699 to 619 lines. Docs/protocol/essay functions become one-liners returning component names. Example functions use sx_call to pass data values to the template. Reference functions pass data-built component trees via SxExpr. renders.py: removed _code, _example_code, _placeholder, _clear_components_btn (now handled by .sx templates). helpers.py: removed inline hero code building, uses ~sx-home-content. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
111 lines
3.7 KiB
Python
111 lines
3.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
|
|
|
|
|
|
def home_content_sx() -> str:
|
|
"""Home page content as sx wire format."""
|
|
return (
|
|
'(section :id "main-panel"'
|
|
' :class "flex-1 md:h-full md:min-h-0 overflow-y-auto overscroll-contain js-grid-viewport"'
|
|
' (~sx-home-content))'
|
|
)
|
|
|
|
|
|
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
|
|
|
|
register_page_helpers("sx", {
|
|
# Content builders
|
|
"home-content": lambda: "(~sx-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,
|
|
})
|