Skip to main content

Module builtin

Module builtin 

Source
Expand description

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!.

These ship with sensible defaults and a minimal HTML template so the editor + render path produce a working page on day one. Hosts can override the template by registering a same-named template before the bundled load — Tera resolves the most-recently-added template, which is the standard precedence rule.

Structs§

BooleanBlock
boolean — Single checkbox; the template renders nothing by default (host overrides decide what “true” means in context — show a banner, flip a class, …).
ChoiceBlock
choice — Editor picks one entry from a host-supplied list of (value, label) pairs. Hosts override Block::fields by subclassing to set their own option list (the registered default lands as an empty select — actionable only when a host extends).
CodeBlock
code — a fenced code block with a language hint. Renders the standard <pre><code class="language-…"> markup that client highlighters (Prism / highlight.js / Shiki) pick up automatically. The body is HTML-escaped by Tera, so it displays verbatim and can’t inject markup. Server-side highlighting (syntect) would add a heavy dependency and is better as an opt-in follow-up — this markup is highlighter-agnostic.
DateBlock
date — ISO-8601 date string (YYYY-MM-DD).
DateTimeBlock
datetime — ISO-8601 datetime string.
DecimalBlock
decimal — Like FloatBlock but the default ships with a stable step="any" hint via the Float widget. Hosts that need bounded precision pass a custom BlockFieldMeta via the with_meta setter (chained at registration time on a subclassed variant). Storage is the decimal as a string so banking-grade precision round-trips through serde without f64 loss.
DocumentChooserBlock
document_chooser — Picks a non-image cms_media row (e.g. PDF, archive) via the modal DocumentChooser widget. Stored value is the media id as a stringified integer.
EmailBlock
email — Browser-validates the shape via <input type="email">; the template renders a mailto: link.
EmbedBlock
embed — A single URL; the public template renders a responsive embed. Self::extra_context runs the URL through crate::embed::resolve so a YouTube watch or Vimeo page URL becomes the provider’s embeddable src with the right aspect ratio; unrecognised URLs link out rather than iframing an arbitrary site.
FloatBlock
float — Free-form floating-point input. Distinct from IntegerBlock (which uses WidgetKind::Number with step="1") — this one accepts decimals.
HeadingBlock
heading — a heading with a level choice. Two fields: text (the heading body) and level (2..4, defaulting to H2). Template emits <h{level}>{text}</h{level}>.
ImageBlock
image — Picks a cms_media row
IntegerBlock
integer — Numeric input; the template renders the value as-is. Editors needing a unit / formatting override the template.
MultipleChoiceBlock
multiple_choice — Distinct from ChoiceBlock (single-pick <select>) — this one renders stacked checkboxes and stores a JSON-array string. Hosts register a subclassed variant with their own option list (default ships with no options, like ChoiceBlock).
PageChooserBlock
page_chooser — Picks a single cms_page row via the modal PageChooser widget; stores the page id as a stringified integer.
ParagraphBlock
paragraph — One markdown field rendered through the rcms safe-markdown pipeline on the public side.
QuoteBlock
quote — Textarea body + optional attribution.
RawHtmlBlock
raw_html — Editor types HTML; the public template sanitises through the same ammonia pipeline as the Markdown widget (crate::markdown::render’s post-pass) so <script> / <iframe> / on* handlers are stripped.
RegexBlock
regex — Text input with a pattern validator. The default ships pattern-less (accepts anything); hosts subclass + override fields() to attach a regex via BlockFieldMeta::default().pattern("^[A-Z]+$"). The browser validates on submit via HTML5 pattern.
RichTextBlock
rich_text — Editor surface for hosts wiring a WYSIWYG (EasyMDE / TipTap / Draftail) via the WidgetKind::RichText widget’s data-widget-mode="richtext" hook. Without a host enhancer the textarea ships with the existing markdown toolbar — same editor as ParagraphBlock but stores HTML directly.
SnippetChooserBlock
snippet_chooser — Picks a cms_snippet row via the modal SnippetChooser widget. The stored value is the snippet id as a stringified integer.
StaticBlock
static — Marker block with no fields; the public template emits whatever static HTML the host wants (divider, call-out, branded heading rule). Inserting one in a StreamField is the editor’s signal “render the host’s static content here”.
TableBlock
table — Editor enters TSV (one row per line, tab-separated cells); the public template renders a <table> with the first row as <thead>. Cells preserve as plain text. Pasting straight from a spreadsheet works because Excel / Google Sheets / Numbers all serialise selected ranges as TSV on the clipboard.
TextBlock
text — Multi-line plain text rendered inside <p> with newlines preserved.
TimeBlock
time — ISO HH:MM[:SS] string.
TypedTableBlock
typed_table — Schema-driven typed grid where each row’s cells are individually-typed widgets (unlike TableBlock which is TSV-only).
TypedTableRowBlock
typed_table_row — one row inside the default TypedTableBlock. Three columns: label (text), value (number), notes (text). This serves as a working baseline; hosts that need a different column schema register their own row block + their own TypedTable-style wrapper.
UrlBlock
url — Browser-validates via <input type="url">; the template renders an anchor.

Functions§

safe_href
An author-typed link target, or None when it would run script.