Skip to main content

Module registry

Module registry 

Source
Expand description

Third-party custom widget registry.

Out-of-tree crates ship new widget types via register_widget!. Each registration carries the wire-format name (used by crate::widget::WidgetKind::Custom and looked up at render time) and the Tera template path the bundled _widget.html macro should include for that name.

§Why no JS class

A widget needs no client-side class keyed by a string name that could fail at runtime if mismatched. The plumbing here is just a Tera template — the same one the server uses to render the widget. Native HTML5 inputs cover most needs (<input type="color">, <input type="date">, <input type="range">); for the rare widget that wants client-side sprinkle (e.g. a map preview reacting to lat/lng inputs), the template can emit a <script> tag inline or a data-* hook the host app’s own bundle reads. No framework-imposed JS class registry.

§Example

ⓘ
use rustango_cms::register_widget;
register_widget!("latlng", "widgets/latlng.html");

Inside a PageTypeHandler::extension_fields impl:

ⓘ
Widget::new(
    WidgetKind::Custom { name: "latlng".to_owned() },
    "office_loc",
    "Office location",
)

Structs§

CustomWidgetRegistration
One registered custom widget — wire-format name paired with the Tera template that renders it. Submitted via register_widget! and collected at startup by the inventory crate.

Functions§

duplicate_widget_names
Surface duplicate registrations at boot. Returns the list of duplicate names; the empty Vec means clean. Host apps should call this once at startup and panic / log on non-empty output — silent duplicates would lead to one of two competing templates winning arbitrarily depending on link order.
find_custom_widget
Look up the registered template path for a custom widget by name. Returns None when the name isn’t registered — callers (the _widget.html macro path) treat this as an editor-visible error rather than panicking.
registered_widgets
Iterator over every registered custom widget. Returned references are 'static — registrations are process-global.
validate_registry
Boot-time validation hook: checks for duplicate widget names.