Expand description
Compile-time HTML rendering, document layout, HTMX helpers, and CSRF tokens for Slabs.
This crate re-exports html! (aliased as maud! in slabs::prelude) so handlers build
auto-escaped HTML at compile time with zero runtime template engine.
§Document layout
document renders a complete HTML5 page with native view transitions
(@view-transition { navigation: auto; }), vendored Basecoat UI styles and scripts
(/_slabs/vendor/basecoat.min.css and /_slabs/vendor/basecoat.min.js), HTMX 2 with the SSE
and Idiomorph extensions (hx-ext="morph" on <body>), and Alpine.js 3.
Pass app-compiled Tailwind CSS v4 stylesheets (for example &ctx.assets.stylesheet_urls()) and
module scripts via the stylesheets and scripts arguments.
All frontend assets are self-hosted with zero CDN or Node runtime requirement.
§HTMX helpers
The htmx module emits standard HX-* headers and hx-swap-oob fragments:
htmx::redirecttriggers a full navigation viaHX-Redirect.htmx::with_triggerattaches anHX-Triggerclient event header to a fragment.htmx::oob,htmx::oob_replace, andhtmx::oob_deletewrap out-of-band DOM swaps.htmx::is_htmxandhtmx::wants_jsoninspectHX-RequestandAcceptheaders.
§CSRF protection
Use csrf_token to mint a signed token bound to a session scope and verify_csrf to check
submitted tokens.
§Usage
use axum::http::HeaderMap;
use axum::response::IntoResponse;
use slabs_html::{document, html, htmx};
fn render_notice(headers: &HeaderMap, styles: &[String]) -> axum::response::Response {
let fragment = html! {
p id="notice" { "Saved." }
};
if htmx::is_htmx(headers) {
return htmx::oob_replace("notice", fragment).into_response();
}
document("Notice", styles, &[], fragment).into_response()
}Modules§
- htmx
- Standard HTMX 2 helpers for
HX-*headers,hx-swap-oobfragments, and signed flash cookies.
Macros§
Structs§
- Flash
- One-shot feedback message carried across a redirect in a signed cookie.
- PreEscaped
- A wrapper that renders the inner value without escaping.
Enums§
Constants§
- DOCTYPE
- The literal string
<!DOCTYPE html>. - FLASH_
COOKIE_ NAME - Cookie name used to store one-shot signed flash messages.
Traits§
- Render
- Represents a type that can be rendered as HTML.
Functions§
- csrf_
token - Generate an HMAC-signed CSRF token bound to
scope(such as a session ID or"anon"). - document
- Render a complete HTML5 page around
bodyusing compile-timeMarkup. - escape
- Escape
&,<,>,", and'into HTML entities for manually assembled strings. - flash_
banner - Render a Basecoat alert banner for an optional
Flashmessage. - render_
markdown - Render untrusted
CommonMarkand GitHub-flavored Markdown into safeMarkup. - verify_
csrf - Verify a submitted CSRF token against
scope.
Type Aliases§
- Markup
- A block of markup is a string that does not need to be escaped.