Route Helpers
Helper utilities for resource monitoring route handlers
Card Container Wrapper
Wrap card content in a styled container for consistent presentation.
wrap_card_in_container
wrap_card_in_container (content, html_id, card_cls=None, bg_cls=None, shadow_cls=None, **kwargs)
Wrap card content in a Div container with standard styling. This consolidates the common pattern of wrapping monitoring cards in styled containers.
| Type | Default | Details | |
|---|---|---|---|
| content | Card content to wrap | ||
| html_id | HTML ID for the container | ||
| card_cls | NoneType | None | Card class (optional, can be provided via DaisyUI) |
| bg_cls | NoneType | None | Background class (optional, can be provided via DaisyUI) |
| shadow_cls | NoneType | None | Shadow class (optional, can be provided via Tailwind) |
| kwargs | VAR_KEYWORD |
Example usage with DaisyUI and Tailwind:
from cjm_fasthtml_daisyui.components.data_display.card import card
from cjm_fasthtml_daisyui.utilities.semantic_colors import bg_dui
from cjm_fasthtml_tailwind.utilities.effects import shadow
wrapped = wrap_card_in_container(
my_card_content,
html_id="my-card",
card_cls=card,
bg_cls=bg_dui.base_100,
shadow_cls=shadow.md
)OOB Card Update Helper
Create out-of-band (OOB) swap updates for cards in SSE streaming.
create_card_update
create_card_update (render_fn:Callable, info:Dict[str,Any], target_id:str, swap_type:str='outerHTML')
Create an OOB swap update for a card. This consolidates the pattern of creating OOB swaps for card updates in SSE streaming.
| Type | Default | Details | |
|---|---|---|---|
| render_fn | Callable | Function to render the card | |
| info | Dict | Info dictionary to pass to render function | |
| target_id | str | Target HTML ID for the swap | |
| swap_type | str | outerHTML | Type of swap |
Example usage in SSE streaming:
from cjm_fasthtml_sysmon.components.cards import render_cpu_card
from cjm_fasthtml_sysmon.monitors.cpu import get_cpu_info
# In your SSE streaming function
async def stream_updates():
while True:
cpu_info = get_cpu_info()
# Create OOB update for CPU card
update = create_card_update(
render_cpu_card,
cpu_info,
"cpu-card-body"
)
yield sse_message(Div(update))
await asyncio.sleep(2)These helpers reduce boilerplate code when working with resource monitoring routes and SSE updates. They provide a consistent pattern while remaining flexible enough to work with different styling libraries and update strategies.