Expand description
Library snippets — reusable, non-page content addressable by slug.
Snippets are the bridge between Library types (the trait-shape
registrations from crate::library) and live pages: editors
create a snippet under a given type, give it a slug, and any
template can pull it back via {{ cms_snippet(slug="hero-cta") }}.
Storage uses one generic cms_snippet table (rather than per-type
extension tables) so adding a new LibraryTypeHandler doesn’t
require migrating tables — typed fields go in the data JSON
column when the registered type wants more than title + body.
The slug is unique tenant-wide so cms_snippet(slug="hero-cta")
resolves without needing the caller to know the type. Pass
type_name= when slugs collide across types.
Structs§
- Snippet
- A single reusable content block. One row per snippet instance.
- Snippet
Revision - Snippets
Guard - Clears the installed snippet maps on drop. Returned by
install.
Functions§
- capture_
revision - Capture one revision row for
snippet. Bumpssequenceoff the current max for that snippet id. Idempotent in the sense that repeated calls produce one row per call — callers should only invoke after a successful save. - child_
folders - All direct child folders of
parent— walks every snippet’sfolder_path, keeps only the segment immediately underparent, dedupes + sorts. Emptyparentmeans root. - folder_
tree_ for_ type - Every folder path used by snippets of
type_name, plus every intermediate folder derived from the leaf paths. Result is sorted and includes the empty (root) folder. - install
- Install the render’s prefetched snippets (from
prefetch_all) forcms_snippet(slug=…), until the guard drops. - normalize_
folder - Normalize a user-typed folder path into the storage form:
no leading slash, single trailing slash on non-empty paths,
collapsed runs of slashes, and segment trim. Empty input
(or
/) → root (""). - prefetch_
all - Prefetch every snippet for the current tenant and return two
slug → htmlmaps (wrapped + inline). The public-render flow inserts them into the Tera context so{{ cms_snippet(slug=…) }}resolves without re-entering the DB. - register_
tera_ function - Register the
cms_snippetTera function. Wired fromcrate::urls::register_tera_helpers. - revision_
by_ sequence - Fetch one revision by
(snippet_id, sequence). ReturnsNonewhen no matching row exists. - revisions_
for - Every revision row for
snippet_id, newest first. - set_
element_ template - Write (or clear) an element’s own template name in its
data.