Fix examples.sx: paren balance + dict eval crash at startup
1. Extra closing paren in ex-tabs handler 2. tab-content dict values contained (div ...) HTML tags which crash during register_components since HTML primitives aren't in env Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -35,6 +35,7 @@ def _register_sx_helpers() -> None:
|
||||
"prove-data": _prove_data,
|
||||
"page-helpers-demo-data": _page_helpers_demo_data,
|
||||
"spec-explorer-data": _spec_explorer_data,
|
||||
"handler-source": _handler_source,
|
||||
})
|
||||
|
||||
|
||||
@@ -68,6 +69,35 @@ def _component_source(name: str) -> str:
|
||||
})
|
||||
|
||||
|
||||
def _handler_source(name: str) -> str:
|
||||
"""Return the pretty-printed defhandler source for a named handler."""
|
||||
from shared.sx.handlers import get_handler
|
||||
from shared.sx.parser import serialize
|
||||
|
||||
hdef = get_handler("sx", name)
|
||||
if not hdef:
|
||||
return f";;; Handler not found: {name}"
|
||||
|
||||
parts = [f"(defhandler {hdef.name}"]
|
||||
if hdef.path:
|
||||
parts.append(f' :path "{hdef.path}"')
|
||||
if hdef.method != "get":
|
||||
parts.append(f" :method :{hdef.method}")
|
||||
if not hdef.csrf:
|
||||
parts.append(" :csrf false")
|
||||
if hdef.returns != "element":
|
||||
parts.append(f' :returns "{hdef.returns}"')
|
||||
param_strs = ["&key"] + list(hdef.params) if hdef.params else []
|
||||
parts.append(f" ({' '.join(param_strs)})" if param_strs else " ()")
|
||||
body_sx = serialize(hdef.body, pretty=True)
|
||||
# Indent body by 2 spaces
|
||||
body_lines = body_sx.split("\n")
|
||||
parts.append(" " + body_lines[0])
|
||||
for line in body_lines[1:]:
|
||||
parts.append(" " + line)
|
||||
return "\n".join(parts) + ")"
|
||||
|
||||
|
||||
def _primitives_data() -> dict:
|
||||
"""Return the PRIMITIVES dict for the primitives docs page."""
|
||||
from content.pages import PRIMITIVES
|
||||
|
||||
Reference in New Issue
Block a user