Core utilities and reusable patterns for FastHTML applications including page layouts, HTMX request handling, alerts, and navbar components.
Project description
cjm-fasthtml-app-core
Install
pip install cjm_fasthtml_app_core
Project Structure
nbs/
├── components/ (2)
│ ├── alerts.ipynb # Alert components for displaying success, error, warning, and info messages
│ └── navbar.ipynb # Responsive navigation bar components with mobile support
└── core/ (3)
├── 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
Total: 5 notebooks across 2 directories
Module Dependencies
graph LR
components_alerts[components.alerts<br/>Alerts]
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]
components_alerts --> core_html_ids
components_navbar --> core_html_ids
core_layout --> core_html_ids
3 cross-module dependencies detected
CLI Reference
No CLI commands found in this project.
Module Overview
Detailed documentation for each module in the project:
Alerts (alerts.ipynb)
Alert components for displaying success, error, warning, and info messages
Import
from cjm_fasthtml_app_core.components.alerts import (
create_success_alert,
create_error_alert,
create_warning_alert,
create_info_alert
)
Functions
def _create_auto_dismiss_script(
timeout_ms:int=3000 # Time in milliseconds before auto-dismiss
) -> FT: # Script element for auto-dismissing alerts
"Create a script that auto-dismisses the alert after a timeout."
def create_success_alert(
message:str, # The success message to display
timeout_ms:int=3000 # Time in milliseconds before auto-dismiss
) -> FT: # Div element containing the success alert
"Create a success alert that auto-dismisses."
def create_error_alert(
message:str, # The error message to display
details:Optional[str]=None # Optional additional details text
) -> FT: # Div element containing the error alert
"Create an error alert with optional details."
def create_warning_alert(
message: str, # The warning message to display
details: Optional[str] = None # Optional additional details text
) -> Div: # Div element containing the warning alert
"Create a warning alert with optional details."
def create_info_alert(
message:str, # The info message to display
details:Optional[str]=None # Optional additional details text
) -> FT: # Div element containing the info alert
"Create an info alert with optional details."
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_nav_link,
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."
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."
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.2.tar.gz.
File metadata
- Download URL: cjm_fasthtml_app_core-0.0.2.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a30b304d90d5e704bf12ae4e2eccdf7b308a3f7b42a17ca06624c7127b8725c
|
|
| MD5 |
0d6c7049496bbd5cf7dbdf402099412e
|
|
| BLAKE2b-256 |
55b5c10c029a657efacf7da1e2abaa4d0fca988528eed00fcbd33c18d55c9b2d
|
File details
Details for the file cjm_fasthtml_app_core-0.0.2-py3-none-any.whl.
File metadata
- Download URL: cjm_fasthtml_app_core-0.0.2-py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32853a3c0db2cadbc2d870dd7a549c589a14485ea87bae19fee5a5705cf4c647
|
|
| MD5 |
03c58970ebe514d135647fd7f8523f49
|
|
| BLAKE2b-256 |
d7cd054fd6ccaa1ffbf2c68aefbef339b4f1795d856acd129707e6f0e239097f
|