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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//! Extension point for **custom admin pages**.
//!
//! Authors building on top of `rustango-cms` register a unit-struct
//! handler via [`crate::register_admin_page!`] and it appears as a
//! sidebar entry under its declared [`SidebarSection`]. All registered
//! handlers route through a single dispatcher mounted at
//! `/cms-admin/x/{slug}`; no per-page router scaffolding to maintain.
//!
//! Custom pages inherit the bundled admin chrome — they extend
//! [`rcms_admin/_base.html`](../templates/_base.html) and get the
//! sidebar, topbar, action-bar slot, flash banners, theme tokens,
//! and every class from [`cms.css`](../static/cms.css) for free.
//!
//! ## Example
//!
//! ```ignore
//! use axum::response::Response;
//! use async_trait::async_trait;
//! use rustango_cms::admin::admin_page::{AdminPageCtx, AdminPageHandler, SidebarSection};
//!
//! #[derive(Default)]
//! pub struct ReportsDashboard;
//!
//! #[async_trait]
//! impl AdminPageHandler for ReportsDashboard {
//! fn slug(&self) -> &'static str { "reports" } // → /cms-admin/x/reports
//! fn label(&self) -> &'static str { "Reports" }
//! fn icon(&self) -> Option<&'static str> { Some("insights") }
//! fn section(&self) -> SidebarSection { SidebarSection::Site }
//! async fn render(&self, ctx: AdminPageCtx<'_>) -> Response {
//! // Build a Tera context, render `reports.html` (host-registered),
//! // return the response.
//! todo!()
//! }
//! }
//!
//! rustango_cms::register_admin_page!(ReportsDashboard);
//! ```
use HeaderMap;
use Response;
use Tenant;
use Arc;
/// Where the custom page's sidebar entry lands. Built-ins:
/// `Content`, `Site`, `Settings`. Use `Custom(&'static str)` to spin
/// up a new section heading on demand (e.g. `Custom("Tools")`).
/// Request-scoped context handed to every custom admin page.
/// References rather than owns so the handler doesn't have to clone
/// the Tera instance / per-tenant pool.
/// Trait every custom admin page implements. Compiled-in via the
/// `inventory` registry — see [`crate::register_admin_page!`].
/// Registration entry submitted via `inventory::submit!` by the
/// `register_admin_page!` macro. Mirrors `PageTypeHandlerRegistration`.
collect!;
/// Iterator over every registered handler. Used by the sidebar
/// enumeration in `add_chrome()` and by the route dispatcher.
/// Find a registered handler by `slug`. Returns `None` for unknown
/// slugs — the dispatch route maps that to a 404.