Convert test/cart/blog/market layouts to use _ctx_to_env + render_to_sx_with_env
Phase 4 (Test): Update ~test-layout-full and ~test-detail-layout-full defcomps to use ~root-header with env free variables. Switch render functions to render_to_sx_with_env. Phase 5 (Cart): Convert cart-page, cart-admin, and order render functions. Update cart .sx layout defcomps to use ~root-header from free variables. Phase 6 (Blog): Convert all 7 blog layouts (blog, settings, sub-settings x5). Remove all root_header_sx calls from blog. Phase 7 (Market): Convert market and market-admin layouts plus browse/product render functions. Remove root_header_sx import. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
50
market/sx/layouts.sx
Normal file
50
market/sx/layouts.sx
Normal file
@@ -0,0 +1,50 @@
|
||||
;; Market layout defcomps — root header from env free variables,
|
||||
;; market-specific headers passed as &key params.
|
||||
|
||||
;; --- Browse layout: root + post header + market header ---
|
||||
|
||||
(defcomp ~market-browse-layout-full (&key post-header market-header)
|
||||
(<> (~root-header :cart-mini cart-mini :blog-url blog-url :site-title site-title
|
||||
:app-label app-label :nav-tree nav-tree :auth-menu auth-menu
|
||||
:nav-panel nav-panel :settings-url settings-url :is-admin is-admin)
|
||||
(~header-child-sx :inner (<> post-header market-header))))
|
||||
|
||||
(defcomp ~market-browse-layout-oob (&key oob-header post-header-oob clear-oob)
|
||||
(<> oob-header post-header-oob clear-oob))
|
||||
|
||||
;; --- Product layout: root + post + market + product ---
|
||||
|
||||
(defcomp ~market-product-layout-full (&key post-header market-header product-header)
|
||||
(<> (~root-header :cart-mini cart-mini :blog-url blog-url :site-title site-title
|
||||
:app-label app-label :nav-tree nav-tree :auth-menu auth-menu
|
||||
:nav-panel nav-panel :settings-url settings-url :is-admin is-admin)
|
||||
(~header-child-sx :inner (<> post-header market-header product-header))))
|
||||
|
||||
;; --- Product admin layout: root + post + market + product + admin ---
|
||||
|
||||
(defcomp ~market-product-admin-layout-full (&key post-header market-header product-header admin-header)
|
||||
(<> (~root-header :cart-mini cart-mini :blog-url blog-url :site-title site-title
|
||||
:app-label app-label :nav-tree nav-tree :auth-menu auth-menu
|
||||
:nav-panel nav-panel :settings-url settings-url :is-admin is-admin)
|
||||
(~header-child-sx :inner (<> post-header market-header product-header admin-header))))
|
||||
|
||||
;; --- Market admin layout: root + post + market + market-admin ---
|
||||
|
||||
(defcomp ~market-admin-layout-full (&key post-header market-header admin-header)
|
||||
(<> (~root-header :cart-mini cart-mini :blog-url blog-url :site-title site-title
|
||||
:app-label app-label :nav-tree nav-tree :auth-menu auth-menu
|
||||
:nav-panel nav-panel :settings-url settings-url :is-admin is-admin)
|
||||
(~header-child-sx :inner (<> post-header market-header admin-header))))
|
||||
|
||||
(defcomp ~market-admin-layout-oob (&key market-header-oob admin-oob-header clear-oob)
|
||||
(<> market-header-oob admin-oob-header clear-oob))
|
||||
|
||||
;; --- OOB wrappers ---
|
||||
|
||||
(defcomp ~market-oob-wrap (&key parts)
|
||||
(<> parts))
|
||||
|
||||
;; --- Content wrappers ---
|
||||
|
||||
(defcomp ~market-content-padded (&key content)
|
||||
(<> content (div :class "pb-8")))
|
||||
@@ -6,7 +6,6 @@ from typing import Any
|
||||
from shared.sx.parser import serialize, SxExpr
|
||||
from shared.sx.helpers import (
|
||||
render_to_sx,
|
||||
root_header_sx,
|
||||
post_header_sx as _post_header_sx,
|
||||
post_admin_header_sx,
|
||||
oob_header_sx as _oob_header_sx,
|
||||
@@ -1227,9 +1226,10 @@ async def render_browse_page(ctx: dict) -> str:
|
||||
cards = await _product_cards_sx(ctx)
|
||||
content = await _product_grid(cards)
|
||||
|
||||
hdr = await root_header_sx(ctx)
|
||||
child = "(<> " + await _post_header_sx(ctx) + " " + await _market_header_sx(ctx) + ")"
|
||||
hdr = "(<> " + hdr + " " + await header_child_sx(child) + ")"
|
||||
from shared.sx.helpers import render_to_sx_with_env, _ctx_to_env
|
||||
hdr = await render_to_sx_with_env("market-browse-layout-full", _ctx_to_env(ctx),
|
||||
post_header=SxExpr(await _post_header_sx(ctx)),
|
||||
market_header=SxExpr(await _market_header_sx(ctx)))
|
||||
menu = await _mobile_nav_panel_sx(ctx)
|
||||
filter_sx = await _mobile_filter_summary_sx(ctx)
|
||||
aside_sx = await _desktop_filter_sx(ctx)
|
||||
@@ -1243,12 +1243,13 @@ async def render_browse_oob(ctx: dict) -> str:
|
||||
cards = await _product_cards_sx(ctx)
|
||||
content = await _product_grid(cards)
|
||||
|
||||
oobs = await _oob_header_sx("post-header-child", "market-header-child",
|
||||
oob_hdr = await _oob_header_sx("post-header-child", "market-header-child",
|
||||
await _market_header_sx(ctx))
|
||||
post_hdr = await _post_header_sx(ctx, oob=True)
|
||||
oobs = "(<> " + oobs + " " + post_hdr + " "
|
||||
oobs += _clear_deeper_oob("post-row", "post-header-child",
|
||||
"market-row", "market-header-child") + ")"
|
||||
oobs = await render_to_sx("market-browse-layout-oob",
|
||||
oob_header=SxExpr(oob_hdr),
|
||||
post_header_oob=SxExpr(await _post_header_sx(ctx, oob=True)),
|
||||
clear_oob=SxExpr(_clear_deeper_oob("post-row", "post-header-child",
|
||||
"market-row", "market-header-child")))
|
||||
menu = await _mobile_nav_panel_sx(ctx)
|
||||
filter_sx = await _mobile_filter_summary_sx(ctx)
|
||||
aside_sx = await _desktop_filter_sx(ctx)
|
||||
@@ -1271,11 +1272,11 @@ async def render_product_page(ctx: dict, d: dict) -> str:
|
||||
content = await _product_detail_sx(d, ctx)
|
||||
meta = await _product_meta_sx(d, ctx)
|
||||
|
||||
hdr = await root_header_sx(ctx)
|
||||
post_hdr = await _post_header_sx(ctx)
|
||||
child = "(<> " + post_hdr + " " + await _market_header_sx(ctx) + " " + await _product_header_sx(ctx, d) + ")"
|
||||
hdr_child = await header_child_sx(child)
|
||||
hdr = "(<> " + hdr + " " + hdr_child + ")"
|
||||
from shared.sx.helpers import render_to_sx_with_env, _ctx_to_env
|
||||
hdr = await render_to_sx_with_env("market-product-layout-full", _ctx_to_env(ctx),
|
||||
post_header=SxExpr(await _post_header_sx(ctx)),
|
||||
market_header=SxExpr(await _market_header_sx(ctx)),
|
||||
product_header=SxExpr(await _product_header_sx(ctx, d)))
|
||||
return await full_page_sx(ctx, header_rows=hdr, content=content, meta=meta)
|
||||
|
||||
|
||||
@@ -1283,13 +1284,13 @@ async def render_product_oob(ctx: dict, d: dict) -> str:
|
||||
"""OOB response: product detail."""
|
||||
content = await _product_detail_sx(d, ctx)
|
||||
|
||||
oobs = "(<> " + await _market_header_sx(ctx, oob=True) + " "
|
||||
oob_hdr = await _oob_header_sx("market-header-child", "product-header-child",
|
||||
await _product_header_sx(ctx, d))
|
||||
oobs += oob_hdr + " "
|
||||
oobs += _clear_deeper_oob("post-row", "post-header-child",
|
||||
oobs = await render_to_sx("market-oob-wrap",
|
||||
parts=SxExpr("(<> " + await _market_header_sx(ctx, oob=True) + " "
|
||||
+ await _oob_header_sx("market-header-child", "product-header-child",
|
||||
await _product_header_sx(ctx, d)) + " "
|
||||
+ _clear_deeper_oob("post-row", "post-header-child",
|
||||
"market-row", "market-header-child",
|
||||
"product-row", "product-header-child") + ")"
|
||||
"product-row", "product-header-child") + ")"))
|
||||
menu = await _mobile_nav_panel_sx(ctx)
|
||||
return await oob_page_sx(oobs=oobs, content=content, menu=menu)
|
||||
|
||||
@@ -1302,12 +1303,12 @@ async def render_product_admin_page(ctx: dict, d: dict) -> str:
|
||||
"""Full page: product admin."""
|
||||
content = await _product_detail_sx(d, ctx)
|
||||
|
||||
hdr = await root_header_sx(ctx)
|
||||
post_hdr = await _post_header_sx(ctx)
|
||||
child = "(<> " + post_hdr + " " + await _market_header_sx(ctx)
|
||||
child += " " + await _product_header_sx(ctx, d) + " " + await _product_admin_header_sx(ctx, d) + ")"
|
||||
hdr_child = await header_child_sx(child)
|
||||
hdr = "(<> " + hdr + " " + hdr_child + ")"
|
||||
from shared.sx.helpers import render_to_sx_with_env, _ctx_to_env
|
||||
hdr = await render_to_sx_with_env("market-product-admin-layout-full", _ctx_to_env(ctx),
|
||||
post_header=SxExpr(await _post_header_sx(ctx)),
|
||||
market_header=SxExpr(await _market_header_sx(ctx)),
|
||||
product_header=SxExpr(await _product_header_sx(ctx, d)),
|
||||
admin_header=SxExpr(await _product_admin_header_sx(ctx, d)))
|
||||
return await full_page_sx(ctx, header_rows=hdr, content=content)
|
||||
|
||||
|
||||
@@ -1315,14 +1316,14 @@ async def render_product_admin_oob(ctx: dict, d: dict) -> str:
|
||||
"""OOB response: product admin."""
|
||||
content = await _product_detail_sx(d, ctx)
|
||||
|
||||
oobs = "(<> " + await _product_header_sx(ctx, d, oob=True) + " "
|
||||
oob_hdr = await _oob_header_sx("product-header-child", "product-admin-header-child",
|
||||
await _product_admin_header_sx(ctx, d))
|
||||
oobs += oob_hdr + " "
|
||||
oobs += _clear_deeper_oob("post-row", "post-header-child",
|
||||
oobs = await render_to_sx("market-oob-wrap",
|
||||
parts=SxExpr("(<> " + await _product_header_sx(ctx, d, oob=True) + " "
|
||||
+ await _oob_header_sx("product-header-child", "product-admin-header-child",
|
||||
await _product_admin_header_sx(ctx, d)) + " "
|
||||
+ _clear_deeper_oob("post-row", "post-header-child",
|
||||
"market-row", "market-header-child",
|
||||
"product-row", "product-header-child",
|
||||
"product-admin-row", "product-admin-header-child") + ")"
|
||||
"product-admin-row", "product-admin-header-child") + ")"))
|
||||
return await oob_page_sx(oobs=oobs, content=content)
|
||||
|
||||
|
||||
@@ -1536,18 +1537,20 @@ def _register_market_layouts() -> None:
|
||||
|
||||
|
||||
async def _market_full(ctx: dict, **kw: Any) -> str:
|
||||
hdr = await root_header_sx(ctx)
|
||||
child = "(<> " + await _post_header_sx(ctx) + " " + await _market_header_sx(ctx) + ")"
|
||||
return "(<> " + hdr + " " + await header_child_sx(child) + ")"
|
||||
from shared.sx.helpers import render_to_sx_with_env, _ctx_to_env
|
||||
return await render_to_sx_with_env("market-browse-layout-full", _ctx_to_env(ctx),
|
||||
post_header=SxExpr(await _post_header_sx(ctx)),
|
||||
market_header=SxExpr(await _market_header_sx(ctx)))
|
||||
|
||||
|
||||
async def _market_oob(ctx: dict, **kw: Any) -> str:
|
||||
oobs = await _oob_header_sx("post-header-child", "market-header-child",
|
||||
oob_hdr = await _oob_header_sx("post-header-child", "market-header-child",
|
||||
await _market_header_sx(ctx))
|
||||
oobs = "(<> " + oobs + " " + await _post_header_sx(ctx, oob=True) + " "
|
||||
oobs += _clear_deeper_oob("post-row", "post-header-child",
|
||||
"market-row", "market-header-child") + ")"
|
||||
return oobs
|
||||
return await render_to_sx("market-browse-layout-oob",
|
||||
oob_header=SxExpr(oob_hdr),
|
||||
post_header_oob=SxExpr(await _post_header_sx(ctx, oob=True)),
|
||||
clear_oob=SxExpr(_clear_deeper_oob("post-row", "post-header-child",
|
||||
"market-row", "market-header-child")))
|
||||
|
||||
|
||||
async def _market_mobile(ctx: dict, **kw: Any) -> str:
|
||||
@@ -1555,22 +1558,23 @@ async def _market_mobile(ctx: dict, **kw: Any) -> str:
|
||||
|
||||
|
||||
async def _market_admin_full(ctx: dict, **kw: Any) -> str:
|
||||
from shared.sx.helpers import render_to_sx_with_env, _ctx_to_env
|
||||
selected = kw.get("selected", "")
|
||||
hdr = await root_header_sx(ctx)
|
||||
child = "(<> " + await _post_header_sx(ctx) + " " + await _market_header_sx(ctx) + " "
|
||||
child += await _market_admin_header_sx(ctx, selected=selected) + ")"
|
||||
return "(<> " + hdr + " " + await header_child_sx(child) + ")"
|
||||
return await render_to_sx_with_env("market-admin-layout-full", _ctx_to_env(ctx),
|
||||
post_header=SxExpr(await _post_header_sx(ctx)),
|
||||
market_header=SxExpr(await _market_header_sx(ctx)),
|
||||
admin_header=SxExpr(await _market_admin_header_sx(ctx, selected=selected)))
|
||||
|
||||
|
||||
async def _market_admin_oob(ctx: dict, **kw: Any) -> str:
|
||||
selected = kw.get("selected", "")
|
||||
oobs = "(<> " + await _market_header_sx(ctx, oob=True) + " "
|
||||
oobs += await _oob_header_sx("market-header-child", "market-admin-header-child",
|
||||
await _market_admin_header_sx(ctx, selected=selected)) + " "
|
||||
oobs += _clear_deeper_oob("post-row", "post-header-child",
|
||||
return await render_to_sx("market-admin-layout-oob",
|
||||
market_header_oob=SxExpr(await _market_header_sx(ctx, oob=True)),
|
||||
admin_oob_header=SxExpr(await _oob_header_sx("market-header-child", "market-admin-header-child",
|
||||
await _market_admin_header_sx(ctx, selected=selected))),
|
||||
clear_oob=SxExpr(_clear_deeper_oob("post-row", "post-header-child",
|
||||
"market-row", "market-header-child",
|
||||
"market-admin-row", "market-admin-header-child") + ")"
|
||||
return oobs
|
||||
"market-admin-row", "market-admin-header-child")))
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
|
||||
Reference in New Issue
Block a user