Skip to main content

Module library

Module library 

Source
Expand description

Library — reusable content (renamed from “snippets”).

Library items are non-page records that pages reference by id — authors, FAQ entries, hero banners, callout blocks, etc. The pattern mirrors register_page_type!: each type implements LibraryTypeHandler, registers via the crate::register_library_type! macro, gets a row in cms_library_type, and exposes its own extension table for the actual content.

ⓘ
#[derive(Default)]
pub struct AuthorEntry;

#[async_trait::async_trait]
impl rustango_cms::library::LibraryTypeHandler for AuthorEntry {
    fn app_label(&self) -> &'static str { "blog" }
    fn type_name(&self) -> &'static str { "Author" }
    fn verbose_name(&self) -> &'static str { "Author" }
    fn extension_table(&self) -> Option<&'static str> { Some("blog_author") }
}

rustango_cms::register_library_type!(AuthorEntry);

Structs§

BulkAction
One bulk action exposed above the list table — pair the multi-select checkbox column with a labeled button. Submits as POST /cms-admin/library/{type}/bulk with action=<name>&ids=<id>&ids=<id>...; the handler routes the selection to LibraryTypeHandler::handle_bulk_action.
LibraryType
Registry row keyed on type_name. Seeded on boot from the inventory of register_library_type!-registered handlers, mirroring PageType.
LibraryTypeHandlerRegistration
Handler-registration entry submitted via inventory::submit!. The factory reconstructs the handler at runtime; mirrors PageTypeHandlerRegistration.
MenuPickerEntry
One row contributed by LibraryTypeHandler::menu_picker_entries to the WP-style menu builder’s Library tab. Each entry renders as a draggable picker card; dropping one into the tree creates a MenuItem with external_url = url and label inherited.

Enums§

BulkActionStyle
Visual emphasis for a bulk action button. Maps to the .btn / .btn-outlined / .btn-danger CSS variants.
ListColumn
One column shown in the snippet list view for a given type. A column can be a scalar field on cms_snippet, a data.<key> JSON lookup, a method-field rendered by the handler, or a computed value derived at render time.
ListColumnKind
How a scalar value should render in the list.
OrderDir
Sort direction for LibraryTypeHandler::default_ordering.

Traits§

LibraryTypeHandler
Trait every library type implements. Mirrors crate::PageTypeHandler — same registration story, same per-tenant seeding pass.

Functions§

ensure_library_type_row
Seed cms_library_type rows for every registered handler across every active org. Wire into the same Cli::seed callback the page-type seeder uses.
find_handler
Locate a handler by type_name. Returns None for unknown types — useful for the admin’s lookup-then-route flow.
registered_handlers
Walk every register_library_type!-registered handler. Used by the seeder + admin to enumerate types at runtime.