Expand description
StreamField — composable body blocks.
A Block is one type of node that can sit in a WidgetKind::Stream
list. Each block declares its structural shape via Block::fields
— a Vec<BlockField> of leaves (BlockField::Widget /
BlockField::Computed) and nested containers (BlockField::Stream
/ BlockField::Repeat). The same BlockField enum covers
struct, stream and list blocks
in one recursive shape so the validator + renderer + admin editor
all reuse a single walker.
§JSON wire format
A stream’s stored JSON is an array of {type, id, value} tuples:
[
{ "type": "heading", "id": "550e8400-…", "value": { "text": "Hi" } },
{ "type": "two_column", "id": "…", "value": {
"left": [ {"type": "image", "id": "…", "value": { "media_id": 4 } } ],
"right": [ {"type": "paragraph", "id": "…", "value": { "body": "…" } } ]
}}
]- Multi-field block:
valueis a flat dict keyed byBlockFieldnames. - Single-field block: canonical shape is still
{<name>: <scalar>}, but a bare scalar atvalueis also accepted on the way in. idis a UUID v4 minted client-side on insert; never re-minted on edit.Repeat(homogeneous) stores[{type: item_type, id, value}, …]— same shape asStream, single allowed type.
§A small trait surface
The editor is one Tera macro and a block is one Rust trait, so a
block needs only three required
methods (Block::type_name, Block::verbose_name,
Block::fields) and four optional ones with defaults
(Block::icon, Block::group, Block::version,
Block::template). Block::render and Block::migrate have
generic default impls.
Re-exports§
pub use registry::find_block;pub use registry::registered_blocks;pub use registry::validate_block_registry;pub use registry::BlockRegistration;
Modules§
- admin
- Admin-side editor rendering for
WidgetKind::Streamwidgets. - builtin
- Built-in blocks shipped with rcms. Each one is a single Rust
struct plus a Tera template at
blocks/<type_name>.html(incrate::admin::register_templates). Host crates register additional blocks viacrate::register_block!. - enrich
- Host-registrable async stream enrichment.
- layout
- Layout blocks: Cards, Slider and Gallery, each a list of
items an editor adds one by one (
BlockField::Repeatover an item block:card,slide,gallery_image). - migrate
- Stepwise schema migration for block-stored JSON.
- registry
- Block registry — inventory-collected
Blockconstructors. - render
- Default render path + recursive stream walker.
- tera_
helpers - Public-side
stream_renderTera function. - translate
- Recursive per-leaf translation walker for StreamField content.
Structs§
- Block
Count Constraint - Per-block-type cardinality constraint on a
BlockField::Stream(block counts). Empty (None/None) means “no constraint on this type”. Independent of the stream-widemin/maxalready on the variant. - Block
Field Meta - Per-field validators threaded into the rendered widget’s HTML5
attributes (
minlength,maxlength,pattern,min,max) - Block
Render Ctx - Context handed to
Block::render+ each computed field. Holds the Tera registry (for nestedblock_renderrecursion) and the trust-bag of pre-rendered child HTML the walker assembles bottom-up.
Enums§
- Block
Error - Per-block, sync render error. Stays sync because every render step is pure JSON → HTML — no IO during the rendering pass.
- Block
Field - One declared field inside a block’s structural shape. The four variants together cover struct, stream, list and static blocks — a single recursive enum, walked once, validated once, rendered once.
Traits§
- Block
- One type of node that can sit in a
WidgetKind::Streamlist.