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
blog/sx/layouts.sx
Normal file
50
blog/sx/layouts.sx
Normal file
@@ -0,0 +1,50 @@
|
||||
;; Blog layout defcomps — root header from env free variables,
|
||||
;; blog-specific headers passed as &key params.
|
||||
|
||||
;; --- Blog layout (root + invisible blog header) ---
|
||||
|
||||
(defcomp ~blog-layout-full (&key blog-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)
|
||||
blog-header))
|
||||
|
||||
;; --- Settings layout (root + settings header) ---
|
||||
|
||||
(defcomp ~settings-layout-full (&key settings-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)
|
||||
settings-header))
|
||||
|
||||
;; --- Sub-settings layout (root + settings + sub row) ---
|
||||
|
||||
(defcomp ~sub-settings-layout-full (&key settings-header sub-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)
|
||||
settings-header sub-header))
|
||||
|
||||
(defcomp ~sub-settings-layout-oob (&key settings-header-oob sub-header-oob)
|
||||
(<> settings-header-oob sub-header-oob))
|
||||
|
||||
;; --- Settings nav links (replaces Python _settings_nav_sx loop) ---
|
||||
|
||||
(defcomp ~blog-settings-nav (&key select-colours)
|
||||
(let* ((links (list
|
||||
(dict :endpoint "menu_items.defpage_menu_items_page" :icon "fa fa-bars" :label "Menu Items")
|
||||
(dict :endpoint "snippets.defpage_snippets_page" :icon "fa fa-puzzle-piece" :label "Snippets")
|
||||
(dict :endpoint "blog.tag_groups_admin.defpage_tag_groups_page" :icon "fa fa-tags" :label "Tag Groups")
|
||||
(dict :endpoint "settings.defpage_cache_page" :icon "fa fa-refresh" :label "Cache"))))
|
||||
(<> (map (lambda (lnk)
|
||||
(~nav-link
|
||||
:href (url-for (get lnk "endpoint"))
|
||||
:icon (get lnk "icon")
|
||||
:label (get lnk "label")
|
||||
:select-colours (or select-colours "")))
|
||||
links))))
|
||||
|
||||
;; --- Editor panel wrapper ---
|
||||
|
||||
(defcomp ~blog-editor-panel (&key parts)
|
||||
(<> parts))
|
||||
@@ -144,21 +144,8 @@ async def _settings_header_sx(ctx: dict, *, oob: bool = False) -> str:
|
||||
|
||||
async def _settings_nav_sx(ctx: dict) -> str:
|
||||
from shared.sx.helpers import render_to_sx
|
||||
from quart import url_for as qurl
|
||||
|
||||
select_colours = ctx.get("select_colours", "")
|
||||
parts = []
|
||||
for endpoint, icon, label in [
|
||||
("menu_items.defpage_menu_items_page", "bars", "Menu Items"),
|
||||
("snippets.defpage_snippets_page", "puzzle-piece", "Snippets"),
|
||||
("blog.tag_groups_admin.defpage_tag_groups_page", "tags", "Tag Groups"),
|
||||
("settings.defpage_cache_page", "refresh", "Cache"),
|
||||
]:
|
||||
href = qurl(endpoint)
|
||||
parts.append(await render_to_sx("nav-link",
|
||||
href=href, icon=f"fa fa-{icon}", label=label,
|
||||
select_colours=select_colours))
|
||||
return "(<> " + " ".join(parts) + ")" if parts else ""
|
||||
return await render_to_sx("blog-settings-nav",
|
||||
select_colours=ctx.get("select_colours", ""))
|
||||
|
||||
|
||||
async def _sub_settings_header_sx(row_id: str, child_id: str, href: str,
|
||||
@@ -197,34 +184,34 @@ def _register_blog_layouts() -> None:
|
||||
# --- Blog layout (root + blog header) ---
|
||||
|
||||
async def _blog_full(ctx: dict, **kw: Any) -> str:
|
||||
from shared.sx.helpers import root_header_sx
|
||||
root_hdr = await root_header_sx(ctx)
|
||||
blog_hdr = await _blog_header_sx(ctx)
|
||||
return "(<> " + root_hdr + " " + blog_hdr + ")"
|
||||
from shared.sx.helpers import render_to_sx_with_env, _ctx_to_env
|
||||
from shared.sx.parser import SxExpr
|
||||
return await render_to_sx_with_env("blog-layout-full", _ctx_to_env(ctx),
|
||||
blog_header=SxExpr(await _blog_header_sx(ctx)))
|
||||
|
||||
|
||||
async def _blog_oob(ctx: dict, **kw: Any) -> str:
|
||||
from shared.sx.helpers import root_header_sx, oob_header_sx
|
||||
root_hdr = await root_header_sx(ctx)
|
||||
blog_hdr = await _blog_header_sx(ctx)
|
||||
rows = "(<> " + root_hdr + " " + blog_hdr + ")"
|
||||
from shared.sx.helpers import render_to_sx_with_env, _ctx_to_env, oob_header_sx
|
||||
from shared.sx.parser import SxExpr
|
||||
rows = await render_to_sx_with_env("blog-layout-full", _ctx_to_env(ctx),
|
||||
blog_header=SxExpr(await _blog_header_sx(ctx)))
|
||||
return await oob_header_sx("root-header-child", "blog-header-child", rows)
|
||||
|
||||
|
||||
# --- Settings layout (root + settings header) ---
|
||||
|
||||
async def _settings_full(ctx: dict, **kw: Any) -> str:
|
||||
from shared.sx.helpers import root_header_sx
|
||||
root_hdr = await root_header_sx(ctx)
|
||||
settings_hdr = await _settings_header_sx(ctx)
|
||||
return "(<> " + root_hdr + " " + settings_hdr + ")"
|
||||
from shared.sx.helpers import render_to_sx_with_env, _ctx_to_env
|
||||
from shared.sx.parser import SxExpr
|
||||
return await render_to_sx_with_env("settings-layout-full", _ctx_to_env(ctx),
|
||||
settings_header=SxExpr(await _settings_header_sx(ctx)))
|
||||
|
||||
|
||||
async def _settings_oob(ctx: dict, **kw: Any) -> str:
|
||||
from shared.sx.helpers import root_header_sx, oob_header_sx
|
||||
root_hdr = await root_header_sx(ctx)
|
||||
settings_hdr = await _settings_header_sx(ctx)
|
||||
rows = "(<> " + root_hdr + " " + settings_hdr + ")"
|
||||
from shared.sx.helpers import render_to_sx_with_env, _ctx_to_env, oob_header_sx
|
||||
from shared.sx.parser import SxExpr
|
||||
rows = await render_to_sx_with_env("settings-layout-full", _ctx_to_env(ctx),
|
||||
settings_header=SxExpr(await _settings_header_sx(ctx)))
|
||||
return await oob_header_sx("root-header-child", "root-settings-header-child", rows)
|
||||
|
||||
|
||||
@@ -236,24 +223,27 @@ async def _settings_mobile(ctx: dict, **kw: Any) -> str:
|
||||
|
||||
async def _sub_settings_full(ctx: dict, row_id: str, child_id: str,
|
||||
endpoint: str, icon: str, label: str) -> str:
|
||||
from shared.sx.helpers import root_header_sx
|
||||
from shared.sx.helpers import render_to_sx_with_env, _ctx_to_env
|
||||
from shared.sx.parser import SxExpr
|
||||
from quart import url_for as qurl
|
||||
root_hdr = await root_header_sx(ctx)
|
||||
settings_hdr = await _settings_header_sx(ctx)
|
||||
sub_hdr = await _sub_settings_header_sx(row_id, child_id,
|
||||
qurl(endpoint), icon, label, ctx)
|
||||
return "(<> " + root_hdr + " " + settings_hdr + " " + sub_hdr + ")"
|
||||
return await render_to_sx_with_env("sub-settings-layout-full", _ctx_to_env(ctx),
|
||||
settings_header=SxExpr(await _settings_header_sx(ctx)),
|
||||
sub_header=SxExpr(await _sub_settings_header_sx(
|
||||
row_id, child_id, qurl(endpoint), icon, label, ctx)))
|
||||
|
||||
|
||||
async def _sub_settings_oob(ctx: dict, row_id: str, child_id: str,
|
||||
endpoint: str, icon: str, label: str) -> str:
|
||||
from shared.sx.helpers import oob_header_sx
|
||||
from shared.sx.helpers import oob_header_sx, render_to_sx
|
||||
from shared.sx.parser import SxExpr
|
||||
from quart import url_for as qurl
|
||||
settings_hdr_oob = await _settings_header_sx(ctx, oob=True)
|
||||
sub_hdr = await _sub_settings_header_sx(row_id, child_id,
|
||||
qurl(endpoint), icon, label, ctx)
|
||||
sub_hdr = await _sub_settings_header_sx(
|
||||
row_id, child_id, qurl(endpoint), icon, label, ctx)
|
||||
sub_oob = await oob_header_sx("root-settings-header-child", child_id, sub_hdr)
|
||||
return "(<> " + settings_hdr_oob + " " + sub_oob + ")"
|
||||
return await render_to_sx("sub-settings-layout-oob",
|
||||
settings_header_oob=SxExpr(settings_hdr_oob),
|
||||
sub_header_oob=SxExpr(sub_oob))
|
||||
|
||||
|
||||
# --- Cache ---
|
||||
@@ -308,26 +298,31 @@ async def _tag_groups_oob(ctx: dict, **kw: Any) -> str:
|
||||
|
||||
async def _tag_group_edit_full(ctx: dict, **kw: Any) -> str:
|
||||
from quart import request, url_for as qurl
|
||||
from shared.sx.helpers import root_header_sx
|
||||
from shared.sx.helpers import render_to_sx_with_env, _ctx_to_env
|
||||
from shared.sx.parser import SxExpr
|
||||
g_id = (request.view_args or {}).get("id")
|
||||
root_hdr = await root_header_sx(ctx)
|
||||
settings_hdr = await _settings_header_sx(ctx)
|
||||
sub_hdr = await _sub_settings_header_sx("tag-groups-row", "tag-groups-header-child",
|
||||
qurl("defpage_tag_group_edit", id=g_id),
|
||||
"tags", "Tag Groups", ctx)
|
||||
return "(<> " + root_hdr + " " + settings_hdr + " " + sub_hdr + ")"
|
||||
return await render_to_sx_with_env("sub-settings-layout-full", _ctx_to_env(ctx),
|
||||
settings_header=SxExpr(await _settings_header_sx(ctx)),
|
||||
sub_header=SxExpr(await _sub_settings_header_sx(
|
||||
"tag-groups-row", "tag-groups-header-child",
|
||||
qurl("defpage_tag_group_edit", id=g_id),
|
||||
"tags", "Tag Groups", ctx)))
|
||||
|
||||
|
||||
async def _tag_group_edit_oob(ctx: dict, **kw: Any) -> str:
|
||||
from quart import request, url_for as qurl
|
||||
from shared.sx.helpers import oob_header_sx
|
||||
from shared.sx.helpers import oob_header_sx, render_to_sx
|
||||
from shared.sx.parser import SxExpr
|
||||
g_id = (request.view_args or {}).get("id")
|
||||
settings_hdr_oob = await _settings_header_sx(ctx, oob=True)
|
||||
sub_hdr = await _sub_settings_header_sx("tag-groups-row", "tag-groups-header-child",
|
||||
qurl("defpage_tag_group_edit", id=g_id),
|
||||
"tags", "Tag Groups", ctx)
|
||||
sub_hdr = await _sub_settings_header_sx(
|
||||
"tag-groups-row", "tag-groups-header-child",
|
||||
qurl("defpage_tag_group_edit", id=g_id),
|
||||
"tags", "Tag Groups", ctx)
|
||||
sub_oob = await oob_header_sx("root-settings-header-child", "tag-groups-header-child", sub_hdr)
|
||||
return "(<> " + settings_hdr_oob + " " + sub_oob + ")"
|
||||
return await render_to_sx("sub-settings-layout-oob",
|
||||
settings_header_oob=SxExpr(settings_hdr_oob),
|
||||
sub_header_oob=SxExpr(sub_oob))
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -512,7 +507,9 @@ async def render_editor_panel(save_error: str | None = None, is_page: bool = Fal
|
||||
sx_editor_js_src=sx_editor_js,
|
||||
init_js=init_js))
|
||||
|
||||
return "(<> " + " ".join(parts) + ")" if parts else ""
|
||||
from shared.sx.parser import SxExpr
|
||||
return await render_to_sx("blog-editor-panel",
|
||||
parts=SxExpr("(<> " + " ".join(parts) + ")")) if parts else ""
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -1116,6 +1113,7 @@ async def _h_post_edit_content(slug=None, **kw):
|
||||
sx_editor_js_src=sx_editor_js,
|
||||
init_js=init_js))
|
||||
|
||||
return "(<> " + " ".join(parts) + ")"
|
||||
return await render_to_sx("blog-editor-panel",
|
||||
parts=SxExpr("(<> " + " ".join(parts) + ")"))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user