Events: 3861 → 21 lines, split into 8 sub-modules (renders, helpers, layouts, calendar, entries, slots, tickets, utils). Updated 16 bp routes. SX Docs: 3224 → 27 lines, split into 5 sub-modules (renders, utils, essays, helpers, layouts). Updated 37 import sites in bp/pages/routes.py. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
113 lines
4.2 KiB
Python
113 lines
4.2 KiB
Python
"""Layout registration and header/mobile functions for sx docs."""
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from .utils import _main_nav_sx, _sx_header_sx, _sub_row_sx
|
|
|
|
def _register_sx_layouts() -> None:
|
|
"""Register the sx docs layout presets."""
|
|
from shared.sx.layouts import register_custom_layout
|
|
|
|
register_custom_layout("sx", _sx_full_headers, _sx_oob_headers, _sx_mobile)
|
|
register_custom_layout("sx-section", _sx_section_full_headers, _sx_section_oob_headers, _sx_section_mobile)
|
|
|
|
|
|
async def _sx_full_headers(ctx: dict, **kw: Any) -> str:
|
|
"""Full headers for sx home page: root + sx menu row."""
|
|
from shared.sx.helpers import render_to_sx_with_env, _ctx_to_env
|
|
from shared.sx.parser import SxExpr
|
|
|
|
main_nav = await _main_nav_sx(kw.get("section"))
|
|
sx_row = await _sx_header_sx(main_nav)
|
|
return await render_to_sx_with_env("sx-layout-full", _ctx_to_env(ctx),
|
|
sx_row=SxExpr(sx_row))
|
|
|
|
|
|
async def _sx_oob_headers(ctx: dict, **kw: Any) -> str:
|
|
"""OOB headers for sx home page."""
|
|
from shared.sx.helpers import render_to_sx_with_env, _ctx_to_env, oob_header_sx
|
|
from shared.sx.parser import SxExpr
|
|
|
|
main_nav = await _main_nav_sx(kw.get("section"))
|
|
sx_row = await _sx_header_sx(main_nav)
|
|
rows = await render_to_sx_with_env("sx-layout-full", _ctx_to_env(ctx),
|
|
sx_row=SxExpr(sx_row))
|
|
return await oob_header_sx("root-header-child", "sx-header-child", rows)
|
|
|
|
|
|
async def _sx_section_full_headers(ctx: dict, **kw: Any) -> str:
|
|
"""Full headers for sx section pages: root + sx row + sub row."""
|
|
from shared.sx.helpers import render_to_sx_with_env, _ctx_to_env
|
|
from shared.sx.parser import SxExpr
|
|
|
|
section = kw.get("section", "")
|
|
sub_label = kw.get("sub_label", section)
|
|
sub_href = kw.get("sub_href", "/")
|
|
sub_nav = kw.get("sub_nav", "")
|
|
selected = kw.get("selected", "")
|
|
|
|
main_nav = await _main_nav_sx(section)
|
|
sub_row = await _sub_row_sx(sub_label, sub_href, sub_nav, selected)
|
|
sx_row = await _sx_header_sx(main_nav, child=sub_row)
|
|
return await render_to_sx_with_env("sx-section-layout-full", _ctx_to_env(ctx),
|
|
sx_row=SxExpr(sx_row))
|
|
|
|
|
|
async def _sx_section_oob_headers(ctx: dict, **kw: Any) -> str:
|
|
"""OOB headers for sx section pages."""
|
|
from shared.sx.helpers import render_to_sx_with_env, _ctx_to_env, oob_header_sx
|
|
from shared.sx.parser import SxExpr
|
|
|
|
section = kw.get("section", "")
|
|
sub_label = kw.get("sub_label", section)
|
|
sub_href = kw.get("sub_href", "/")
|
|
sub_nav = kw.get("sub_nav", "")
|
|
selected = kw.get("selected", "")
|
|
|
|
main_nav = await _main_nav_sx(section)
|
|
sub_row = await _sub_row_sx(sub_label, sub_href, sub_nav, selected)
|
|
sx_row = await _sx_header_sx(main_nav, child=sub_row)
|
|
rows = await render_to_sx_with_env("sx-section-layout-full", _ctx_to_env(ctx),
|
|
sx_row=SxExpr(sx_row))
|
|
return await oob_header_sx("root-header-child", "sx-header-child", rows)
|
|
|
|
|
|
async def _sx_mobile(ctx: dict, **kw: Any) -> str:
|
|
"""Mobile menu for sx home page: main nav + root."""
|
|
from shared.sx.helpers import (
|
|
mobile_menu_sx, mobile_root_nav_sx, render_to_sx, SxExpr,
|
|
)
|
|
|
|
main_nav = await _main_nav_sx(kw.get("section"))
|
|
return mobile_menu_sx(
|
|
await render_to_sx("mobile-menu-section",
|
|
label="sx", href="/", level=1, colour="violet",
|
|
items=SxExpr(main_nav)),
|
|
await mobile_root_nav_sx(ctx),
|
|
)
|
|
|
|
|
|
async def _sx_section_mobile(ctx: dict, **kw: Any) -> str:
|
|
"""Mobile menu for sx section pages: sub nav + main nav + root."""
|
|
from shared.sx.helpers import (
|
|
mobile_menu_sx, mobile_root_nav_sx, render_to_sx, SxExpr,
|
|
)
|
|
|
|
section = kw.get("section", "")
|
|
sub_label = kw.get("sub_label", section)
|
|
sub_href = kw.get("sub_href", "/")
|
|
sub_nav = kw.get("sub_nav", "")
|
|
main_nav = await _main_nav_sx(section)
|
|
|
|
parts = []
|
|
if sub_nav:
|
|
parts.append(await render_to_sx("mobile-menu-section",
|
|
label=sub_label, href=sub_href, level=2, colour="violet",
|
|
items=SxExpr(sub_nav)))
|
|
parts.append(await render_to_sx("mobile-menu-section",
|
|
label="sx", href="/", level=1, colour="violet",
|
|
items=SxExpr(main_nav)))
|
|
parts.append(await mobile_root_nav_sx(ctx))
|
|
return mobile_menu_sx(*parts)
|