1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//! Third-party custom widget registry.
//!
//! Out-of-tree crates ship new widget types via
//! [`register_widget!`](crate::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
//!
//! ```ignore
//! use rustango_cms::register_widget;
//! register_widget!("latlng", "widgets/latlng.html");
//! ```
//!
//! Inside a `PageTypeHandler::extension_fields` impl:
//!
//! ```ignore
//! Widget::new(
//! WidgetKind::Custom { name: "latlng".to_owned() },
//! "office_loc",
//! "Office location",
//! )
//! ```
/// One registered custom widget — wire-format `name` paired with the
/// Tera template that renders it. Submitted via [`register_widget!`](crate::register_widget!)
/// and collected at startup by the [`inventory`] crate.
collect!;
/// Register a custom widget at module-load time. Picks up
/// `rustango_cms::inventory` (re-exported in [`crate`]) so callers
/// don't need their own `inventory` dep.
///
/// ```ignore
/// use rustango_cms::register_widget;
/// register_widget!("latlng", "widgets/latlng.html");
/// ```
/// Iterator over every registered custom widget. Returned references
/// are `'static` — registrations are process-global.
/// 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.
/// 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.
/// Boot-time validation hook: checks for duplicate widget names.
///
/// # Panics
/// On any duplicate widget name — boot-time crash with both
/// occupants named is the right loud failure.