Skip to main content

Module block

Module block 

Source
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: value is a flat dict keyed by BlockField names.
  • Single-field block: canonical shape is still {<name>: <scalar>}, but a bare scalar at value is also accepted on the way in.
  • id is a UUID v4 minted client-side on insert; never re-minted on edit.
  • Repeat (homogeneous) stores [{type: item_type, id, value}, …] — same shape as Stream, 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::Stream widgets.
builtin
Built-in blocks shipped with rcms. Each one is a single Rust struct plus a Tera template at blocks/<type_name>.html (in crate::admin::register_templates). Host crates register additional blocks via crate::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::Repeat over an item block: card, slide, gallery_image).
migrate
Stepwise schema migration for block-stored JSON.
registry
Block registry — inventory-collected Block constructors.
render
Default render path + recursive stream walker.
tera_helpers
Public-side stream_render Tera function.
translate
Recursive per-leaf translation walker for StreamField content.

Structs§

BlockCountConstraint
Per-block-type cardinality constraint on a BlockField::Stream (block counts). Empty (None / None) means “no constraint on this type”. Independent of the stream-wide min / max already on the variant.
BlockFieldMeta
Per-field validators threaded into the rendered widget’s HTML5 attributes (minlength, maxlength, pattern, min, max)
BlockRenderCtx
Context handed to Block::render + each computed field. Holds the Tera registry (for nested block_render recursion) and the trust-bag of pre-rendered child HTML the walker assembles bottom-up.

Enums§

BlockError
Per-block, sync render error. Stays sync because every render step is pure JSON → HTML — no IO during the rendering pass.
BlockField
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::Stream list.