cjm-fasthtml-app-core


Namecjm-fasthtml-app-core JSON
Version 0.0.3 PyPI version JSON
download
home_pagehttps://github.com/cj-mills/cjm-fasthtml-app-core
SummaryCore utilities and reusable patterns for FastHTML applications including page layouts, HTMX request handling, alerts, and navbar components.
upload_time2025-10-27 22:50:54
maintainerNone
docs_urlNone
authorChristian J. Mills
requires_python>=3.11
licenseApache Software License 2.0
keywords nbdev jupyter notebook python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # cjm-fasthtml-app-core


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

## Install

``` bash
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/ (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

``` mermaid
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]
    core_routing[core.routing<br/>routing]

    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

``` python
from cjm_fasthtml_app_core.components.alerts import (
    create_success_alert,
    create_error_alert,
    create_warning_alert,
    create_info_alert
)
```

#### Functions

``` python
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."
```

``` python
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."
```

``` python
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."
```

``` python
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."
```

``` python
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

``` python
from cjm_fasthtml_app_core.core.html_ids import (
    AppHtmlIds
)
```

#### Classes

``` python
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

``` python
from cjm_fasthtml_app_core.core.htmx import (
    is_htmx_request,
    handle_htmx_request
)
```

#### Functions

``` python
def is_htmx_request(
    request # FastHTML request object
) -> bool: # True if request is from HTMX
    "Check if a request is an HTMX request."
```

``` python
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

``` python
from cjm_fasthtml_app_core.core.layout import (
    wrap_with_layout
)
```

#### Functions

``` python
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

``` python
from cjm_fasthtml_app_core.components.navbar import (
    create_nav_link,
    create_navbar
)
```

#### Functions

``` python
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."
```

``` python
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

``` python
from cjm_fasthtml_app_core.core.routing import (
    register_routes
)
```

#### Functions

```` python
def register_routes(
    app,  # FastHTML app instance
    *routers  # One or more APIRouter instances to register
) -> None
    """
    Register multiple APIRouter instances to a FastHTML app at once.
    
    This is a convenience function that replaces multiple `.to_app(app)` calls
    with a single function call.
    
    Example:
        ```python
        from fasthtml.common import *
        from cjm_fasthtml_app_core.core.routing import register_routes
        
        # Create routers
        main_ar = APIRouter(prefix="/")
        settings_ar = APIRouter(prefix="/settings")
        api_ar = APIRouter(prefix="/api")
        
        # Instead of:
        # main_ar.to_app(app)
        # settings_ar.to_app(app)
        # api_ar.to_app(app)
        
        # Do this:
        register_routes(app, main_ar, settings_ar, api_ar)
        ```
    """
````

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/cj-mills/cjm-fasthtml-app-core",
    "name": "cjm-fasthtml-app-core",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "nbdev jupyter notebook python",
    "author": "Christian J. Mills",
    "author_email": "9126128+cj-mills@users.noreply.github.com",
    "download_url": "https://files.pythonhosted.org/packages/b4/20/025138478b47668fcf04954797b55c0dd97140de8731b3d2c99e134e3c3a/cjm_fasthtml_app_core-0.0.3.tar.gz",
    "platform": null,
    "description": "# cjm-fasthtml-app-core\n\n\n<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->\n\n## Install\n\n``` bash\npip install cjm_fasthtml_app_core\n```\n\n## Project Structure\n\n    nbs/\n    \u251c\u2500\u2500 components/ (2)\n    \u2502   \u251c\u2500\u2500 alerts.ipynb  # Alert components for displaying success, error, warning, and info messages\n    \u2502   \u2514\u2500\u2500 navbar.ipynb  # Responsive navigation bar components with mobile support\n    \u2514\u2500\u2500 core/ (4)\n        \u251c\u2500\u2500 html_ids.ipynb  # Base HTML ID constants for FastHTML applications\n        \u251c\u2500\u2500 htmx.ipynb      # Utilities for handling HTMX requests and responses\n        \u251c\u2500\u2500 layout.ipynb    # Page layout utilities for wrapping content with common page structure\n        \u2514\u2500\u2500 routing.ipynb   # Routing utilities for FastHTML applications\n\nTotal: 6 notebooks across 2 directories\n\n## Module Dependencies\n\n``` mermaid\ngraph LR\n    components_alerts[components.alerts<br/>Alerts]\n    components_navbar[components.navbar<br/>Navbar]\n    core_html_ids[core.html_ids<br/>HTML IDs]\n    core_htmx[core.htmx<br/>HTMX Utilities]\n    core_layout[core.layout<br/>Layout]\n    core_routing[core.routing<br/>routing]\n\n    components_alerts --> core_html_ids\n    components_navbar --> core_html_ids\n    core_layout --> core_html_ids\n```\n\n*3 cross-module dependencies detected*\n\n## CLI Reference\n\nNo CLI commands found in this project.\n\n## Module Overview\n\nDetailed documentation for each module in the project:\n\n### Alerts (`alerts.ipynb`)\n\n> Alert components for displaying success, error, warning, and info\n> messages\n\n#### Import\n\n``` python\nfrom cjm_fasthtml_app_core.components.alerts import (\n    create_success_alert,\n    create_error_alert,\n    create_warning_alert,\n    create_info_alert\n)\n```\n\n#### Functions\n\n``` python\ndef _create_auto_dismiss_script(\n    timeout_ms:int=3000 # Time in milliseconds before auto-dismiss\n) -> FT: # Script element for auto-dismissing alerts\n    \"Create a script that auto-dismisses the alert after a timeout.\"\n```\n\n``` python\ndef create_success_alert(\n    message:str, # The success message to display\n    timeout_ms:int=3000 # Time in milliseconds before auto-dismiss\n) -> FT: # Div element containing the success alert\n    \"Create a success alert that auto-dismisses.\"\n```\n\n``` python\ndef create_error_alert(\n    message:str, # The error message to display\n    details:Optional[str]=None # Optional additional details text\n) -> FT: # Div element containing the error alert\n    \"Create an error alert with optional details.\"\n```\n\n``` python\ndef create_warning_alert(\n    message: str,  # The warning message to display\n    details: Optional[str] = None  # Optional additional details text\n) -> Div:  # Div element containing the warning alert\n    \"Create a warning alert with optional details.\"\n```\n\n``` python\ndef create_info_alert(\n    message:str, # The info message to display\n    details:Optional[str]=None # Optional additional details text\n) -> FT: # Div element containing the info alert\n    \"Create an info alert with optional details.\"\n```\n\n### HTML IDs (`html_ids.ipynb`)\n\n> Base HTML ID constants for FastHTML applications\n\n#### Import\n\n``` python\nfrom cjm_fasthtml_app_core.core.html_ids import (\n    AppHtmlIds\n)\n```\n\n#### Classes\n\n``` python\nclass AppHtmlIds:\n    \"Base HTML ID constants for FastHTML applications.\"\n    \n    def as_selector(\n            id_str:str # The HTML ID to convert\n        ) -> str: # CSS selector with # prefix\n        \"Convert an ID to a CSS selector format.\"\n```\n\n### HTMX Utilities (`htmx.ipynb`)\n\n> Utilities for handling HTMX requests and responses\n\n#### Import\n\n``` python\nfrom cjm_fasthtml_app_core.core.htmx import (\n    is_htmx_request,\n    handle_htmx_request\n)\n```\n\n#### Functions\n\n``` python\ndef is_htmx_request(\n    request # FastHTML request object\n) -> bool: # True if request is from HTMX\n    \"Check if a request is an HTMX request.\"\n```\n\n``` python\ndef handle_htmx_request(\n    request, # FastHTML request object\n    content_fn:Callable, # Function to generate content\n    *args, # Positional arguments for content_fn\n    wrap_fn:Optional[Callable]=None, # Optional wrapper function for full page requests\n    **kwargs # Keyword arguments for content_fn\n): # Content or wrapped content based on request type\n    \"Handle HTMX vs full page response pattern.\"\n```\n\n### Layout (`layout.ipynb`)\n\n> Page layout utilities for wrapping content with common page structure\n\n#### Import\n\n``` python\nfrom cjm_fasthtml_app_core.core.layout import (\n    wrap_with_layout\n)\n```\n\n#### Functions\n\n``` python\ndef wrap_with_layout(\n    content:FT, # The main content to display\n    navbar:Optional[FT]=None, # Optional navbar component\n    footer:Optional[FT]=None, # Optional footer component\n    container_id:str=AppHtmlIds.MAIN_CONTENT, # ID for the main content container\n    container_tag:str=\"div\" # HTML tag for the container\n) -> FT: # Main element with navbar and content\n    \"Wrap content with the full page layout including optional navbar and footer.\"\n```\n\n### Navbar (`navbar.ipynb`)\n\n> Responsive navigation bar components with mobile support\n\n#### Import\n\n``` python\nfrom cjm_fasthtml_app_core.components.navbar import (\n    create_nav_link,\n    create_navbar\n)\n```\n\n#### Functions\n\n``` python\ndef create_nav_link(\n    label:str, # Link text to display\n    route, # FastHTML route object with .to() method\n    target_id:str=AppHtmlIds.MAIN_CONTENT # HTMX target container ID\n) -> FT: # Anchor element with HTMX attributes\n    \"Create a navigation link with HTMX attributes for SPA-like behavior.\"\n```\n\n``` python\ndef create_navbar(\n    title:str, # Application title\n    nav_items:List[Tuple[str, Any]], # List of (label, route) tuples\n    home_route:Optional[Any]=None, # Optional home route for title link\n    theme_selector:bool=True, # Whether to include theme selector\n    target_id:str=AppHtmlIds.MAIN_CONTENT, # HTMX target container ID\n    **navbar_kwargs # Additional kwargs for navbar styling\n) -> FT: # Navbar component\n    \"Create a responsive navigation bar with mobile dropdown menu.\"\n```\n\n### routing (`routing.ipynb`)\n\n> Routing utilities for FastHTML applications\n\n#### Import\n\n``` python\nfrom cjm_fasthtml_app_core.core.routing import (\n    register_routes\n)\n```\n\n#### Functions\n\n```` python\ndef register_routes(\n    app,  # FastHTML app instance\n    *routers  # One or more APIRouter instances to register\n) -> None\n    \"\"\"\n    Register multiple APIRouter instances to a FastHTML app at once.\n    \n    This is a convenience function that replaces multiple `.to_app(app)` calls\n    with a single function call.\n    \n    Example:\n        ```python\n        from fasthtml.common import *\n        from cjm_fasthtml_app_core.core.routing import register_routes\n        \n        # Create routers\n        main_ar = APIRouter(prefix=\"/\")\n        settings_ar = APIRouter(prefix=\"/settings\")\n        api_ar = APIRouter(prefix=\"/api\")\n        \n        # Instead of:\n        # main_ar.to_app(app)\n        # settings_ar.to_app(app)\n        # api_ar.to_app(app)\n        \n        # Do this:\n        register_routes(app, main_ar, settings_ar, api_ar)\n        ```\n    \"\"\"\n````\n",
    "bugtrack_url": null,
    "license": "Apache Software License 2.0",
    "summary": "Core utilities and reusable patterns for FastHTML applications including page layouts, HTMX request handling, alerts, and navbar components.",
    "version": "0.0.3",
    "project_urls": {
        "Homepage": "https://github.com/cj-mills/cjm-fasthtml-app-core"
    },
    "split_keywords": [
        "nbdev",
        "jupyter",
        "notebook",
        "python"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "964be9ccb6b0dcb93f0558a2581869b7f9c8b471a9c7299ea25ceb3be2ba7a12",
                "md5": "53876e62f4bdcbc39aea5b288598bdd4",
                "sha256": "379d38357f85c66156e2715cdbb404f90b4d260eb66cc61b005a0a8cef194682"
            },
            "downloads": -1,
            "filename": "cjm_fasthtml_app_core-0.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "53876e62f4bdcbc39aea5b288598bdd4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 15988,
            "upload_time": "2025-10-27T22:50:53",
            "upload_time_iso_8601": "2025-10-27T22:50:53.512183Z",
            "url": "https://files.pythonhosted.org/packages/96/4b/e9ccb6b0dcb93f0558a2581869b7f9c8b471a9c7299ea25ceb3be2ba7a12/cjm_fasthtml_app_core-0.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "b420025138478b47668fcf04954797b55c0dd97140de8731b3d2c99e134e3c3a",
                "md5": "3c2b7614924cb10e5a99fa3b789ffba3",
                "sha256": "274c4e89b177b3877ea9d74770653b8409ff0e79184660b3570af2d7606302de"
            },
            "downloads": -1,
            "filename": "cjm_fasthtml_app_core-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "3c2b7614924cb10e5a99fa3b789ffba3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 15083,
            "upload_time": "2025-10-27T22:50:54",
            "upload_time_iso_8601": "2025-10-27T22:50:54.755705Z",
            "url": "https://files.pythonhosted.org/packages/b4/20/025138478b47668fcf04954797b55c0dd97140de8731b3d2c99e134e3c3a/cjm_fasthtml_app_core-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-27 22:50:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cj-mills",
    "github_project": "cjm-fasthtml-app-core",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "cjm-fasthtml-app-core"
}
        
Elapsed time: 1.00744s