Fix sx docs pages leaking raw s-expressions and missing sub-row
Three issues fixed: - async_eval_slot_to_sx (and async_eval_to_sx) was calling serialize() on plain strings returned by page helpers, quoting them as literals instead of treating them as sx source. Added str check to wrap directly in SxExpr. - _render_to_sx_with_env passed layout kwargs only as env free variables, but _aser_component defaults all declared params to NIL regardless of env. Now builds the AST with extra_env entries as keyword args so they bind through normal param mechanism. - _nav_items_sx returned plain str; changed to SxExpr so nav fragments serialize unquoted when passed as layout kwargs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1013,6 +1013,8 @@ async def async_eval_to_sx(
|
|||||||
return result
|
return result
|
||||||
if result is None or result is NIL:
|
if result is None or result is NIL:
|
||||||
return SxExpr("")
|
return SxExpr("")
|
||||||
|
if isinstance(result, str):
|
||||||
|
return SxExpr(result)
|
||||||
return SxExpr(serialize(result))
|
return SxExpr(serialize(result))
|
||||||
|
|
||||||
|
|
||||||
@@ -1042,6 +1044,8 @@ async def async_eval_slot_to_sx(
|
|||||||
return result
|
return result
|
||||||
if result is None or result is NIL:
|
if result is None or result is NIL:
|
||||||
return SxExpr("")
|
return SxExpr("")
|
||||||
|
if isinstance(result, str):
|
||||||
|
return SxExpr(result)
|
||||||
return SxExpr(serialize(result))
|
return SxExpr(serialize(result))
|
||||||
else:
|
else:
|
||||||
import logging
|
import logging
|
||||||
@@ -1059,6 +1063,9 @@ async def async_eval_slot_to_sx(
|
|||||||
return result
|
return result
|
||||||
if result is None or result is NIL:
|
if result is None or result is NIL:
|
||||||
return SxExpr("")
|
return SxExpr("")
|
||||||
|
if isinstance(result, str):
|
||||||
|
# Plain strings from page helpers are already sx source — don't quote.
|
||||||
|
return SxExpr(result)
|
||||||
return SxExpr(serialize(result))
|
return SxExpr(serialize(result))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -347,8 +347,19 @@ async def _render_to_sx_with_env(__name: str, extra_env: dict, **kwargs: Any) ->
|
|||||||
"""
|
"""
|
||||||
from .jinja_bridge import get_component_env, _get_request_context
|
from .jinja_bridge import get_component_env, _get_request_context
|
||||||
from .async_eval import async_eval_slot_to_sx
|
from .async_eval import async_eval_slot_to_sx
|
||||||
|
from .types import Symbol, Keyword, NIL as _NIL
|
||||||
|
|
||||||
|
# Build AST with extra_env entries as keyword args so _aser_component
|
||||||
|
# binds them as params (otherwise it defaults all params to NIL).
|
||||||
|
comp_sym = Symbol(__name if __name.startswith("~") else f"~{__name}")
|
||||||
|
ast: list = [comp_sym]
|
||||||
|
for k, v in extra_env.items():
|
||||||
|
ast.append(Keyword(k))
|
||||||
|
ast.append(v if v is not None else _NIL)
|
||||||
|
for k, v in kwargs.items():
|
||||||
|
ast.append(Keyword(k.replace("_", "-")))
|
||||||
|
ast.append(v if v is not None else _NIL)
|
||||||
|
|
||||||
ast = _build_component_ast(__name, **kwargs)
|
|
||||||
env = dict(get_component_env())
|
env = dict(get_component_env())
|
||||||
env.update(extra_env)
|
env.update(extra_env)
|
||||||
ctx = _get_request_context()
|
ctx = _get_request_context()
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from shared.sx.helpers import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _nav_items_sx(items: list[tuple[str, str]], current: str | None = None) -> str:
|
def _nav_items_sx(items: list[tuple[str, str]], current: str | None = None) -> SxExpr:
|
||||||
"""Build nav link items as sx."""
|
"""Build nav link items as sx."""
|
||||||
parts = []
|
parts = []
|
||||||
for label, href in items:
|
for label, href in items:
|
||||||
@@ -15,7 +15,7 @@ def _nav_items_sx(items: list[tuple[str, str]], current: str | None = None) -> s
|
|||||||
is_selected="true" if current == label else None,
|
is_selected="true" if current == label else None,
|
||||||
select_colours="aria-selected:bg-violet-200 aria-selected:text-violet-900",
|
select_colours="aria-selected:bg-violet-200 aria-selected:text-violet-900",
|
||||||
))
|
))
|
||||||
return "(<> " + " ".join(parts) + ")"
|
return SxExpr("(<> " + " ".join(parts) + ")")
|
||||||
|
|
||||||
|
|
||||||
def _doc_nav_sx(items: list[tuple[str, str]], current: str) -> str:
|
def _doc_nav_sx(items: list[tuple[str, str]], current: str) -> str:
|
||||||
|
|||||||
Reference in New Issue
Block a user