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:
@@ -170,6 +170,15 @@
|
||||
(summary :class "cursor-pointer px-4 py-3 font-medium text-sm bg-stone-100 hover:bg-stone-200 select-none" title)
|
||||
(div :class "p-4 overflow-x-auto text-xs" content)))
|
||||
|
||||
(defcomp ~blog-preview-rendered (&key html)
|
||||
(div :class "blog-content prose max-w-none" (raw! html)))
|
||||
|
||||
(defcomp ~blog-preview-empty ()
|
||||
(div :class "p-8 text-stone-500" "No content to preview."))
|
||||
|
||||
(defcomp ~blog-admin-placeholder ()
|
||||
(div :class "pb-8"))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; Data-driven content defcomps (called from defpages with service data)
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
||||
@@ -1,37 +1,38 @@
|
||||
;; Blog layout defcomps — root header from env free variables,
|
||||
;; blog-specific headers passed as &key params.
|
||||
;; Blog layout defcomps — fully self-contained via IO primitives.
|
||||
|
||||
;; --- Blog layout (root + invisible blog header) ---
|
||||
;; --- Blog header (invisible row for blog-header-child swap target) ---
|
||||
|
||||
(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))
|
||||
(defcomp ~blog-header (&key oob)
|
||||
(~menu-row-sx :id "blog-row" :level 1
|
||||
:link-label-content (div)
|
||||
:child-id "blog-header-child" :oob oob))
|
||||
|
||||
;; --- Blog layout (root + blog header) ---
|
||||
|
||||
(defcomp ~blog-layout-full ()
|
||||
(<> (~root-header-auto)
|
||||
(~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)
|
||||
(<> (~root-header-auto)
|
||||
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)
|
||||
(<> (~root-header-auto)
|
||||
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) ---
|
||||
;; --- Settings nav links — uses (select-colours) IO primitive ---
|
||||
|
||||
(defcomp ~blog-settings-nav (&key select-colours)
|
||||
(let* ((links (list
|
||||
(defcomp ~blog-settings-nav ()
|
||||
(let* ((sc (select-colours))
|
||||
(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")
|
||||
@@ -41,7 +42,7 @@
|
||||
:href (url-for (get lnk "endpoint"))
|
||||
:icon (get lnk "icon")
|
||||
:label (get lnk "label")
|
||||
:select-colours (or select-colours "")))
|
||||
:select-colours (or sc "")))
|
||||
links))))
|
||||
|
||||
;; --- Editor panel wrapper ---
|
||||
|
||||
@@ -140,7 +140,8 @@ async def _h_editor_page_content(**kw):
|
||||
|
||||
async def _h_post_admin_content(slug=None, **kw):
|
||||
await _ensure_post_data(slug)
|
||||
return '(div :class "pb-8")'
|
||||
from shared.sx.helpers import render_to_sx
|
||||
return await render_to_sx("blog-admin-placeholder")
|
||||
|
||||
|
||||
async def _h_post_data_content(slug=None, **kw):
|
||||
@@ -264,7 +265,7 @@ async def _h_post_preview_content(slug=None, **kw):
|
||||
from quart import g
|
||||
from shared.services.registry import services
|
||||
from shared.sx.helpers import render_to_sx
|
||||
from shared.sx.parser import SxExpr, serialize as sx_serialize
|
||||
from shared.sx.parser import SxExpr
|
||||
|
||||
preview = await services.blog_page.preview_data(g.s)
|
||||
|
||||
@@ -276,16 +277,16 @@ async def _h_post_preview_content(slug=None, **kw):
|
||||
sections.append(await render_to_sx("blog-preview-section",
|
||||
title="Lexical JSON", content=SxExpr(preview["json_pretty"])))
|
||||
if preview.get("sx_rendered"):
|
||||
rendered_sx = f'(div :class "blog-content prose max-w-none" (raw! {sx_serialize(preview["sx_rendered"])}))'
|
||||
rendered_sx = await render_to_sx("blog-preview-rendered", html=preview["sx_rendered"])
|
||||
sections.append(await render_to_sx("blog-preview-section",
|
||||
title="SX Rendered", content=SxExpr(rendered_sx)))
|
||||
if preview.get("lex_rendered"):
|
||||
rendered_sx = f'(div :class "blog-content prose max-w-none" (raw! {sx_serialize(preview["lex_rendered"])}))'
|
||||
rendered_sx = await render_to_sx("blog-preview-rendered", html=preview["lex_rendered"])
|
||||
sections.append(await render_to_sx("blog-preview-section",
|
||||
title="Lexical Rendered", content=SxExpr(rendered_sx)))
|
||||
|
||||
if not sections:
|
||||
return '(div :class "p-8 text-stone-500" "No content to preview.")'
|
||||
return await render_to_sx("blog-preview-empty")
|
||||
|
||||
inner = " ".join(sections)
|
||||
return await render_to_sx("blog-preview-panel", sections=SxExpr(f"(<> {inner})"))
|
||||
|
||||
@@ -8,15 +8,6 @@ from typing import Any
|
||||
# Header helpers (moved from sx_components — thin render_to_sx wrappers)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def _blog_header_sx(ctx: dict, *, oob: bool = False) -> str:
|
||||
from shared.sx.helpers import render_to_sx
|
||||
from shared.sx.parser import SxExpr
|
||||
return await render_to_sx("menu-row-sx",
|
||||
id="blog-row", level=1,
|
||||
link_label_content=SxExpr("(div)"),
|
||||
child_id="blog-header-child", oob=oob)
|
||||
|
||||
|
||||
async def _settings_header_sx(ctx: dict, *, oob: bool = False) -> str:
|
||||
from shared.sx.helpers import render_to_sx
|
||||
from shared.sx.parser import SxExpr
|
||||
@@ -36,8 +27,7 @@ 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
|
||||
return await render_to_sx("blog-settings-nav",
|
||||
select_colours=ctx.get("select_colours", ""))
|
||||
return await render_to_sx("blog-settings-nav")
|
||||
|
||||
|
||||
async def _sub_settings_header_sx(row_id: str, child_id: str, href: str,
|
||||
@@ -76,33 +66,29 @@ def _register_blog_layouts() -> None:
|
||||
# --- Blog layout (root + blog header) ---
|
||||
|
||||
async def _blog_full(ctx: dict, **kw: Any) -> str:
|
||||
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)))
|
||||
from shared.sx.helpers import render_to_sx_with_env
|
||||
return await render_to_sx_with_env("blog-layout-full", {})
|
||||
|
||||
|
||||
async def _blog_oob(ctx: dict, **kw: Any) -> str:
|
||||
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)))
|
||||
from shared.sx.helpers import render_to_sx_with_env, oob_header_sx
|
||||
rows = await render_to_sx_with_env("blog-layout-full", {})
|
||||
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 render_to_sx_with_env, _ctx_to_env
|
||||
from shared.sx.helpers import render_to_sx_with_env
|
||||
from shared.sx.parser import SxExpr
|
||||
return await render_to_sx_with_env("settings-layout-full", _ctx_to_env(ctx),
|
||||
return await render_to_sx_with_env("settings-layout-full", {},
|
||||
settings_header=SxExpr(await _settings_header_sx(ctx)))
|
||||
|
||||
|
||||
async def _settings_oob(ctx: dict, **kw: Any) -> str:
|
||||
from shared.sx.helpers import render_to_sx_with_env, _ctx_to_env, oob_header_sx
|
||||
from shared.sx.helpers import render_to_sx_with_env, oob_header_sx
|
||||
from shared.sx.parser import SxExpr
|
||||
rows = await render_to_sx_with_env("settings-layout-full", _ctx_to_env(ctx),
|
||||
rows = await render_to_sx_with_env("settings-layout-full", {},
|
||||
settings_header=SxExpr(await _settings_header_sx(ctx)))
|
||||
return await oob_header_sx("root-header-child", "root-settings-header-child", rows)
|
||||
|
||||
@@ -115,10 +101,10 @@ 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 render_to_sx_with_env, _ctx_to_env
|
||||
from shared.sx.helpers import render_to_sx_with_env
|
||||
from shared.sx.parser import SxExpr
|
||||
from quart import url_for as qurl
|
||||
return await render_to_sx_with_env("sub-settings-layout-full", _ctx_to_env(ctx),
|
||||
return await render_to_sx_with_env("sub-settings-layout-full", {},
|
||||
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)))
|
||||
@@ -190,10 +176,10 @@ 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 render_to_sx_with_env, _ctx_to_env
|
||||
from shared.sx.helpers import render_to_sx_with_env
|
||||
from shared.sx.parser import SxExpr
|
||||
g_id = (request.view_args or {}).get("id")
|
||||
return await render_to_sx_with_env("sub-settings-layout-full", _ctx_to_env(ctx),
|
||||
return await render_to_sx_with_env("sub-settings-layout-full", {},
|
||||
settings_header=SxExpr(await _settings_header_sx(ctx)),
|
||||
sub_header=SxExpr(await _sub_settings_header_sx(
|
||||
"tag-groups-row", "tag-groups-header-child",
|
||||
|
||||
Reference in New Issue
Block a user