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
|
||||
if result is None or result is NIL:
|
||||
return SxExpr("")
|
||||
if isinstance(result, str):
|
||||
return SxExpr(result)
|
||||
return SxExpr(serialize(result))
|
||||
|
||||
|
||||
@@ -1042,6 +1044,8 @@ async def async_eval_slot_to_sx(
|
||||
return result
|
||||
if result is None or result is NIL:
|
||||
return SxExpr("")
|
||||
if isinstance(result, str):
|
||||
return SxExpr(result)
|
||||
return SxExpr(serialize(result))
|
||||
else:
|
||||
import logging
|
||||
@@ -1059,6 +1063,9 @@ async def async_eval_slot_to_sx(
|
||||
return result
|
||||
if result is None or result is NIL:
|
||||
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))
|
||||
|
||||
|
||||
|
||||
@@ -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 .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.update(extra_env)
|
||||
ctx = _get_request_context()
|
||||
|
||||
Reference in New Issue
Block a user