HyperChad HTML Renderer
Server-side HTML renderer for HyperChad with support for multiple web frameworks and deployment targets.
Overview
The HyperChad HTML Renderer provides:
- Server-side Rendering: Generate static and dynamic HTML from HyperChad components
- Framework Integration: Support for Actix Web, Lambda, and generic HTTP servers
- Responsive Design: CSS media queries and responsive breakpoints
- Static Assets: Asset serving and management
- HTML Tag Rendering: Complete HTML element generation with styling
- Partial Updates: HTMX-compatible partial page updates
- SEO Optimization: Server-rendered HTML for search engine optimization
Features
HTML Generation
- Complete HTML Output: Full HTML documents with DOCTYPE, head, and body
- CSS Styling: Inline styles and CSS classes generation
- Responsive CSS: Media queries for responsive design
- Element Attributes: Data attributes, IDs, classes, and custom attributes
- Semantic HTML: Proper semantic HTML element generation
Framework Support
- Actix Web: Full integration with Actix Web framework
- AWS Lambda: Serverless deployment support
- Generic HTTP: Works with any HTTP server implementation
- Static Assets: File serving and asset management
Rendering Modes
- Full Page Rendering: Complete HTML documents
- Partial Rendering: HTMX-compatible partial updates
- Component Rendering: Individual component HTML generation
- Template Rendering: Reusable template rendering
Installation
Add this to your Cargo.toml:
[]
= { = "../hyperchad/renderer/html" }
Enable optional integrations by adding features to the same dependency declaration:
# Actix Web support
= {
path = "../hyperchad/renderer/html",
= ["actix"]
}
# Lambda support
= {
path = "../hyperchad/renderer/html",
= ["lambda"]
}
# Static asset serving
= {
path = "../hyperchad/renderer/html",
= ["assets"]
}
Usage
Basic HTML Rendering with Router
use ;
use Router;
use Renderer;
async
Direct HTML Generation
use ;
use Container;
use BTreeMap;
Actix Web Integration
use ;
use ;
use Router;
use ;
async
Lambda Integration
use ;
use Router;
Responsive Design
use DefaultHtmlTagRenderer;
use ;
// Create tag renderer with responsive breakpoints
let tag_renderer = default
.with_responsive_trigger
.with_responsive_trigger;
// The tag renderer will generate appropriate CSS media queries
// for responsive overrides defined in your HyperChad components
Static Asset Serving
use ;
use ;
use Router;
use PathBuf;
let tag_renderer = default;
let router = default;
// Configure static asset routes
let renderer = router_to_actix
.with_static_asset_routes;
Partial Updates
The HTML renderer supports partial page updates through the View type. When a route returns a View with fragments, the renderer:
- Generates only the updated HTML content for fragments
- Sets custom headers to communicate fragment information
- Works seamlessly with HTMX and similar frameworks
use ;
use Container;
use Selector;
// In your route handler, return a View with fragments
async
Feature Flags
actix: Enable Actix Web integration (impliesextend)lambda: Enable AWS Lambda integrationweb-server: Enable generic web server integration (impliesextend)web-server-actix: Enable Actix-based web server (impliesweb-server)web-server-simulator: Enable simulator-based web server (impliesweb-server)assets: Enable static asset servingextend: Enable renderer extension systemjson: Enable JSON content supportactions: Enable action handling (requiresactix)sse: Enable Server-Sent Events support (requiresactix)debug: Enable debug featuresfail-on-warnings: Treat compiler warnings as errors
HTML Output Features
CSS Generation
- Inline Styles: Component styles rendered as inline CSS attributes
- CSS Classes: Automatic CSS class application from HyperChad components
- Media Queries: Responsive breakpoint CSS via
@mediaqueries - Flexbox & Grid: CSS flexbox and grid layout generation
SEO Optimization
- Semantic HTML: Proper HTML5 semantic elements (div, aside, main, header, footer, section, etc.)
- Meta Tags: Title, description, and viewport meta tags
- Server-side Rendering: Full HTML documents for search engine crawlers
- Accessibility: Proper HTML structure and attributes
Core Dependencies
- hyperchad_renderer: Core renderer traits and types
- hyperchad_router: Routing and navigation system
- hyperchad_transformer: Element transformation and styling
- Maud: Type-safe HTML template generation
- html-escape: Safe HTML escaping
- uaparser: User agent parsing for client detection
- flume: Async channel communication
- switchy: HTTP models and utilities
- hyperchad_renderer_html_actix: Actix Web integration (optional)
- hyperchad_renderer_html_lambda: AWS Lambda integration (optional)
- hyperchad_renderer_html_web_server: Generic web server integration (optional)
Integration
This renderer is designed for:
- Web Applications: Server-side rendered web apps with Actix Web
- Serverless: AWS Lambda deployments
- Microservices: Lightweight HTML rendering services
- SEO-critical Sites: Applications requiring search engine optimization
Architecture
The package provides:
DefaultHtmlTagRenderer: Core HTML tag rendering implementationHtmlRenderer<T>: Generic renderer wrapper for different app typesrouter_to_actix(): Helper to create Actix Web-integrated renderersrouter_to_lambda(): Helper to create Lambda-integrated renderersrouter_to_web_server(): Helper to create generic web server renderers (optional)- Extension System: Via
ExtendHtmlRenderertrait for custom rendering logic
Performance Considerations
- Server-side Rendering: HTML generation happens on the server, reducing client-side work
- Type-safe HTML: Maud provides compile-time HTML validation
- Efficient Rendering: Direct byte-level HTML writing for performance
- Partial Updates: Support for efficient partial page updates