Phase 5: Page layouts as s-expressions — components, fragments, error pages
Add 9 new shared s-expression components (cart-mini, auth-menu, account-nav-item, calendar-entry-nav, calendar-link-nav, market-link-nav, post-card, base-shell, error-page) and wire them into all fragment route handlers. 404/403 error pages now render entirely via s-expressions as a full-page proof-of-concept, with Jinja fallback on failure. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -35,6 +35,10 @@ def register():
|
||||
# --- container-nav fragment: calendar entries + calendar links -----------
|
||||
|
||||
async def _container_nav_handler():
|
||||
from quart import current_app
|
||||
from shared.infrastructure.urls import events_url
|
||||
from shared.sexp.jinja_bridge import sexp as render_sexp
|
||||
|
||||
container_type = request.args.get("container_type", "page")
|
||||
container_id = int(request.args.get("container_id", 0))
|
||||
post_slug = request.args.get("post_slug", "")
|
||||
@@ -43,6 +47,8 @@ def register():
|
||||
exclude = request.args.get("exclude", "")
|
||||
excludes = [e.strip() for e in exclude.split(",") if e.strip()]
|
||||
|
||||
styles = current_app.jinja_env.globals.get("styles", {})
|
||||
nav_class = styles.get("nav_button_less_pad", "")
|
||||
html_parts = []
|
||||
|
||||
# Calendar entries nav
|
||||
@@ -50,23 +56,41 @@ def register():
|
||||
entries, has_more = await services.calendar.associated_entries(
|
||||
g.s, container_type, container_id, page,
|
||||
)
|
||||
if entries:
|
||||
html_parts.append(await render_template(
|
||||
"fragments/container_nav_entries.html",
|
||||
entries=entries, has_more=has_more,
|
||||
page=page, post_slug=post_slug,
|
||||
paginate_url_base=paginate_url_base,
|
||||
for entry in entries:
|
||||
entry_path = (
|
||||
f"/{post_slug}/calendars/{entry.calendar_slug}/"
|
||||
f"{entry.start_at.year}/{entry.start_at.month}/"
|
||||
f"{entry.start_at.day}/entries/{entry.id}/"
|
||||
)
|
||||
date_str = entry.start_at.strftime("%b %d, %Y at %H:%M")
|
||||
if entry.end_at:
|
||||
date_str += f" – {entry.end_at.strftime('%H:%M')}"
|
||||
html_parts.append(render_sexp(
|
||||
'(~calendar-entry-nav :href href :name name :date-str date-str :nav-class nav-class)',
|
||||
href=events_url(entry_path), name=entry.name,
|
||||
**{"date-str": date_str, "nav-class": nav_class},
|
||||
))
|
||||
# Infinite scroll sentinel (kept as raw HTML — HTMX-specific)
|
||||
if has_more and paginate_url_base:
|
||||
html_parts.append(
|
||||
f'<div id="entries-load-sentinel-{page}"'
|
||||
f' hx-get="{paginate_url_base}?page={page + 1}"'
|
||||
f' hx-trigger="intersect once"'
|
||||
f' hx-swap="beforebegin"'
|
||||
f' _="on htmx:afterRequest trigger scroll on #associated-entries-container"'
|
||||
f' class="flex-shrink-0 w-1"></div>'
|
||||
)
|
||||
|
||||
# Calendar links nav
|
||||
if not any(e.startswith("calendar") for e in excludes):
|
||||
calendars = await services.calendar.calendars_for_container(
|
||||
g.s, container_type, container_id,
|
||||
)
|
||||
if calendars:
|
||||
html_parts.append(await render_template(
|
||||
"fragments/container_nav_calendars.html",
|
||||
calendars=calendars, post_slug=post_slug,
|
||||
for cal in calendars:
|
||||
href = events_url(f"/{post_slug}/calendars/{cal.slug}/")
|
||||
html_parts.append(render_sexp(
|
||||
'(~calendar-link-nav :href href :name name :nav-class nav-class)',
|
||||
href=href, name=cal.name, **{"nav-class": nav_class},
|
||||
))
|
||||
|
||||
return "\n".join(html_parts)
|
||||
@@ -99,7 +123,28 @@ def register():
|
||||
# --- account-nav-item fragment: tickets + bookings links for account nav -
|
||||
|
||||
async def _account_nav_item_handler():
|
||||
return await render_template("fragments/account_nav_items.html")
|
||||
from quart import current_app
|
||||
from shared.infrastructure.urls import account_url
|
||||
|
||||
styles = current_app.jinja_env.globals.get("styles", {})
|
||||
nav_class = styles.get("nav_button", "")
|
||||
hx_select = (
|
||||
"#main-panel, #search-mobile, #search-count-mobile,"
|
||||
" #search-desktop, #search-count-desktop, #menu-items-nav-wrapper"
|
||||
)
|
||||
tickets_url = account_url("/tickets/")
|
||||
bookings_url = account_url("/bookings/")
|
||||
# These two links use HTMX navigation — kept as raw HTML for the
|
||||
# hx-* attributes that don't map neatly to a reusable component.
|
||||
parts = []
|
||||
for href, label in [(tickets_url, "tickets"), (bookings_url, "bookings")]:
|
||||
parts.append(
|
||||
f'<div class="relative nav-group">'
|
||||
f'<a href="{href}" hx-get="{href}" hx-target="#main-panel"'
|
||||
f' hx-select="{hx_select}" hx-swap="outerHTML"'
|
||||
f' hx-push-url="true" class="{nav_class}">{label}</a></div>'
|
||||
)
|
||||
return "\n".join(parts)
|
||||
|
||||
_handlers["account-nav-item"] = _account_nav_item_handler
|
||||
|
||||
|
||||
Reference in New Issue
Block a user