Replace env free-variable threading with IO-primitive auto-fetch macros
Layout components now self-resolve context (cart-mini, auth-menu, nav-tree, rights, URLs) via new IO primitives (root-header-ctx, select-colours, account-nav-ctx, app-rights) and defmacro wrappers (~root-header-auto, ~auth-header-row-auto, ~root-mobile-auto). This eliminates _ctx_to_env(), HELPER_CSS_CLASSES, and verbose :key threading across all 10 services. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
;; Market grid and layout components
|
||||
|
||||
(defcomp ~market-markets-grid (&key cards)
|
||||
(div :class "max-w-full px-3 py-3 grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4" cards))
|
||||
(<> (div :class "max-w-full px-3 py-3 grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4" cards) (div :class "pb-8")))
|
||||
|
||||
(defcomp ~market-product-grid (&key cards)
|
||||
(<> (div :class "grid grid-cols-1 sm:grid-cols-3 md:grid-cols-6 gap-3" cards) (div :class "pb-8")))
|
||||
|
||||
(defcomp ~market-admin-content-wrap (&key inner)
|
||||
(div :id "main-panel" inner))
|
||||
|
||||
(defcomp ~market-like-toggle-button (&key colour action hx-headers label icon-cls)
|
||||
(button :class (str "flex items-center gap-1 " colour " hover:text-red-600 transition-colors w-[1em] h-[1em]")
|
||||
:sx-post action :sx-target "this" :sx-swap "outerHTML" :sx-push-url "false"
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
(div :class "font-bold text-xl flex-shrink-0 flex gap-2 items-center"
|
||||
(div (i :class "fa fa-shop") " " title)
|
||||
(div :class "flex flex-col md:flex-row md:gap-2 text-xs"
|
||||
(div top-slug) sub-div)))
|
||||
(div top-slug) (when sub-div (div sub-div)))))
|
||||
|
||||
(defcomp ~market-product-label (&key title)
|
||||
(<> (i :class "fa fa-shopping-bag" :aria-hidden "true") (div title)))
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
;; Market layout defcomps — root header from env free variables,
|
||||
;; Market layout defcomps — root header via ~root-header-auto,
|
||||
;; 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)
|
||||
(<> (~root-header-auto)
|
||||
(~header-child-sx :inner (<> post-header market-header))))
|
||||
|
||||
(defcomp ~market-browse-layout-oob (&key oob-header post-header-oob clear-oob)
|
||||
@@ -15,25 +13,19 @@
|
||||
;; --- 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)
|
||||
(<> (~root-header-auto)
|
||||
(~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)
|
||||
(<> (~root-header-auto)
|
||||
(~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)
|
||||
(<> (~root-header-auto)
|
||||
(~header-child-sx :inner (<> post-header market-header admin-header))))
|
||||
|
||||
(defcomp ~market-admin-layout-oob (&key market-header-oob admin-oob-header clear-oob)
|
||||
|
||||
@@ -122,8 +122,7 @@ async def _h_all_markets_content(**kw):
|
||||
next_url = prefix + url_for("all_markets.markets_fragment", page=page + 1)
|
||||
|
||||
cards = await _market_cards_sx(markets, page_info, page, has_more, next_url)
|
||||
content = await _markets_grid(cards)
|
||||
return "(<> " + content + " " + '(div :class "pb-8")' + ")"
|
||||
return await _markets_grid(cards)
|
||||
|
||||
|
||||
async def _h_page_markets_content(slug=None, **kw):
|
||||
@@ -146,15 +145,16 @@ async def _h_page_markets_content(slug=None, **kw):
|
||||
|
||||
cards = await _market_cards_sx(markets, {}, page, has_more, next_url,
|
||||
show_page_badge=False, post_slug=post_slug)
|
||||
content = await _markets_grid(cards)
|
||||
return "(<> " + content + " " + '(div :class "pb-8")' + ")"
|
||||
return await _markets_grid(cards)
|
||||
|
||||
|
||||
async def _h_page_admin_content(slug=None, **kw):
|
||||
from shared.sx.page import get_template_context
|
||||
from shared.sx.helpers import render_to_sx
|
||||
from shared.sx.parser import SxExpr
|
||||
ctx = await get_template_context()
|
||||
content = await _markets_admin_panel_sx(ctx)
|
||||
return '(div :id "main-panel" ' + content + ')'
|
||||
return await render_to_sx("market-admin-content-wrap", inner=SxExpr(content))
|
||||
|
||||
|
||||
async def _h_market_home_content(page_slug=None, market_slug=None, **kw):
|
||||
|
||||
@@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from shared.sx.parser import serialize, SxExpr
|
||||
from shared.sx.parser import SxExpr
|
||||
from shared.sx.helpers import (
|
||||
render_to_sx,
|
||||
post_header_sx as _post_header_sx,
|
||||
@@ -28,11 +28,10 @@ async def _market_header_sx(ctx: dict, *, oob: bool = False) -> str:
|
||||
sub_slug = ctx.get("sub_slug", "")
|
||||
hx_select_search = ctx.get("hx_select_search", "#main-panel")
|
||||
|
||||
sub_div = f'(div {serialize(sub_slug)})' if sub_slug else ""
|
||||
label_sx = await render_to_sx(
|
||||
"market-shop-label",
|
||||
title=market_title, top_slug=top_slug or "",
|
||||
sub_div=SxExpr(sub_div) if sub_div else None,
|
||||
sub_div=sub_slug or None,
|
||||
)
|
||||
|
||||
link_href = url_for("defpage_market_home")
|
||||
@@ -294,8 +293,8 @@ def _register_market_layouts() -> None:
|
||||
|
||||
|
||||
async def _market_full(ctx: dict, **kw: Any) -> str:
|
||||
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),
|
||||
from shared.sx.helpers import render_to_sx_with_env
|
||||
return await render_to_sx_with_env("market-browse-layout-full", {},
|
||||
post_header=SxExpr(await _post_header_sx(ctx)),
|
||||
market_header=SxExpr(await _market_header_sx(ctx)))
|
||||
|
||||
@@ -315,9 +314,9 @@ 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
|
||||
from shared.sx.helpers import render_to_sx_with_env
|
||||
selected = kw.get("selected", "")
|
||||
return await render_to_sx_with_env("market-admin-layout-full", _ctx_to_env(ctx),
|
||||
return await render_to_sx_with_env("market-admin-layout-full", {},
|
||||
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)))
|
||||
|
||||
@@ -35,8 +35,8 @@ async def render_browse_page(ctx: dict) -> str:
|
||||
cards = await _product_cards_sx(ctx)
|
||||
content = await _product_grid(cards)
|
||||
|
||||
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),
|
||||
from shared.sx.helpers import render_to_sx_with_env
|
||||
hdr = await render_to_sx_with_env("market-browse-layout-full", {},
|
||||
post_header=SxExpr(await _post_header_sx(ctx)),
|
||||
market_header=SxExpr(await _market_header_sx(ctx)))
|
||||
menu = await _mobile_nav_panel_sx(ctx)
|
||||
@@ -81,8 +81,8 @@ async def render_product_page(ctx: dict, d: dict) -> str:
|
||||
content = await _product_detail_sx(d, ctx)
|
||||
meta = await _product_meta_sx(d, ctx)
|
||||
|
||||
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),
|
||||
from shared.sx.helpers import render_to_sx_with_env
|
||||
hdr = await render_to_sx_with_env("market-product-layout-full", {},
|
||||
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)))
|
||||
@@ -112,8 +112,8 @@ async def render_product_admin_page(ctx: dict, d: dict) -> str:
|
||||
"""Full page: product admin."""
|
||||
content = await _product_detail_sx(d, ctx)
|
||||
|
||||
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),
|
||||
from shared.sx.helpers import render_to_sx_with_env
|
||||
hdr = await render_to_sx_with_env("market-product-admin-layout-full", {},
|
||||
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)),
|
||||
|
||||
@@ -22,8 +22,9 @@ _MARKET_DEEP_IDS = [
|
||||
|
||||
def _clear_deeper_oob(*keep_ids: str) -> str:
|
||||
"""Clear all market header rows/children NOT in keep_ids."""
|
||||
from shared.sx.helpers import sx_call
|
||||
to_clear = [i for i in _MARKET_DEEP_IDS if i not in keep_ids]
|
||||
return " ".join(f'(div :id "{i}" :sx-swap-oob "outerHTML")' for i in to_clear)
|
||||
return " ".join(sx_call("clear-oob-div", id=i) for i in to_clear)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user