Core utilities and reusable patterns for FastHTML applications including page layouts, HTMX request handling, navbar, and confirm modal components.
Project description
cjm-fasthtml-app-core
Install
pip install cjm_fasthtml_app_core
Project Structure
nbs/
├── components/ (2)
│ ├── confirm_modal.ipynb # Generic destructive-confirm modal — Cancel-on-left, Confirm-on-right, with backdrop click-to-dismiss and defensive form-submission guards. Codifies **Convention V12 (Destructive-confirm composition)** as running code.
│ └── navbar.ipynb # Responsive navigation bar components with mobile support
└── core/ (4)
├── html_ids.ipynb # Base HTML ID constants for FastHTML applications
├── htmx.ipynb # Utilities for handling HTMX requests and responses
├── layout.ipynb # Page layout utilities for wrapping content with common page structure
└── routing.ipynb # Routing utilities for FastHTML applications
Total: 6 notebooks across 2 directories
Module Dependencies
graph LR
components_confirm_modal[components.confirm_modal<br/>Confirm Modal]
components_navbar[components.navbar<br/>Navbar]
core_html_ids[core.html_ids<br/>HTML IDs]
core_htmx[core.htmx<br/>HTMX Utilities]
core_layout[core.layout<br/>Layout]
core_routing[core.routing<br/>routing]
components_navbar --> core_html_ids
core_layout --> core_html_ids
2 cross-module dependencies detected
CLI Reference
No CLI commands found in this project.
Module Overview
Detailed documentation for each module in the project:
Confirm Modal (confirm_modal.ipynb)
Generic destructive-confirm modal — Cancel-on-left, Confirm-on-right, with backdrop click-to-dismiss and defensive form-submission guards. Codifies Convention V12 (Destructive-confirm composition) as running code.
Import
from cjm_fasthtml_app_core.components.confirm_modal import (
render_confirm_modal
)
Functions
def render_confirm_modal(
modal_id:str, # HTML id for the <dialog> element
body_id:str, # HTML id for the inner Div HTMX targets for message text
title:str="Confirm Action?", # Modal title (rendered in <h3>)
confirm_label:str="Confirm", # Right-button label
confirm_icon:Optional[str]=None, # Optional Lucide icon name (e.g. "trash-2") prefixed to the confirm label
cancel_label:str="Cancel", # Left-button label
confirm_attrs:Optional[Dict[str, Any]]=None, # Caller-supplied attrs for the confirm button (hx_post / hx_vals / hx_swap / etc.)
) -> FT: # Dialog element implementing V12
"Render a destructive-confirm modal (V12). Cancel-LEFT, Confirm-RIGHT, backdrop click-to-dismiss, defensive type=button. Body populated via HTMX swap into body_id."
HTML IDs (html_ids.ipynb)
Base HTML ID constants for FastHTML applications
Import
from cjm_fasthtml_app_core.core.html_ids import (
AppHtmlIds
)
Classes
class AppHtmlIds:
"Base HTML ID constants for FastHTML applications."
def as_selector(
id_str:str # The HTML ID to convert
) -> str: # CSS selector with # prefix
"Convert an ID to a CSS selector format."
HTMX Utilities (htmx.ipynb)
Utilities for handling HTMX requests and responses
Import
from cjm_fasthtml_app_core.core.htmx import (
is_htmx_request,
handle_htmx_request
)
Functions
def is_htmx_request(
request # FastHTML request object
) -> bool: # True if request is from HTMX
"Check if a request is an HTMX request."
def handle_htmx_request(
request, # FastHTML request object
content_fn:Callable, # Function to generate content
*args, # Positional arguments for content_fn
wrap_fn:Optional[Callable]=None, # Optional wrapper function for full page requests
**kwargs # Keyword arguments for content_fn
): # Content or wrapped content based on request type
"Handle HTMX vs full page response pattern."
Layout (layout.ipynb)
Page layout utilities for wrapping content with common page structure
Import
from cjm_fasthtml_app_core.core.layout import (
wrap_with_layout
)
Functions
def wrap_with_layout(
content:FT, # The main content to display
navbar:Optional[FT]=None, # Optional navbar component
footer:Optional[FT]=None, # Optional footer component
container_id:str=AppHtmlIds.MAIN_CONTENT, # ID for the main content container
container_tag:str="div" # HTML tag for the container
) -> FT: # Main element with navbar and content
"Wrap content with the full page layout including optional navbar and footer."
Navbar (navbar.ipynb)
Responsive navigation bar components with mobile support
Import
from cjm_fasthtml_app_core.components.navbar import (
create_navbar
)
Functions
def _create_nav_link(
label:str, # Link text to display
route, # FastHTML route object with .to() method
target_id:str=AppHtmlIds.MAIN_CONTENT # HTMX target container ID
) -> FT: # Anchor element with HTMX attributes
"Create a navigation link with HTMX attributes for SPA-like behavior. Internal helper for `create_navbar`."
def create_navbar(
title:str, # Application title
nav_items:List[Tuple[str, Any]], # List of (label, route) tuples
home_route:Optional[Any]=None, # Optional home route for title link
theme_selector:bool=True, # Whether to include theme selector
target_id:str=AppHtmlIds.MAIN_CONTENT, # HTMX target container ID
**navbar_kwargs # Additional kwargs for navbar styling
) -> FT: # Navbar component
"Create a responsive navigation bar with mobile dropdown menu."
routing (routing.ipynb)
Routing utilities for FastHTML applications
Import
from cjm_fasthtml_app_core.core.routing import (
register_routes
)
Functions
def register_routes(
app, # FastHTML app instance
*routers # One or more APIRouter instances to register
) -> None: # No return value
"Register multiple APIRouter instances to a FastHTML app at once."
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cjm_fasthtml_app_core-0.0.15.tar.gz.
File metadata
- Download URL: cjm_fasthtml_app_core-0.0.15.tar.gz
- Upload date:
- Size: 12.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dbb57bc8af0055e9854c5259fd410f69a94756031bb069d11ad75a9584190f5a
|
|
| MD5 |
e881a7060c0520517857999d0be999ba
|
|
| BLAKE2b-256 |
04edeb7ee5b063b2043b4e801b6aaf068481ffdcfbb44931d59719da9f3e359d
|
File details
Details for the file cjm_fasthtml_app_core-0.0.15-py3-none-any.whl.
File metadata
- Download URL: cjm_fasthtml_app_core-0.0.15-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f47d952e4d6b9fce29000f502623a84ffdcb8f6b7c2d113337469c5b1f7ac02
|
|
| MD5 |
3c36f308b75cf8c159c56dbc078b9a6a
|
|
| BLAKE2b-256 |
4edadef8fd23ddca2c3dc80a887ae5a76483316ec3937be5819c877029a3115d
|