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
//! `rustango-cms-macros` — the derive macros of rustango-cms. Use them
//! through the `rustango_cms` re-exports; this crate is not added on its own.
//!
//! - `#[derive(PageType)]` walks the struct's `#[page_type(...)]` +
//! `#[field(...)]` attributes and emits the full `PageTypeHandler`
//! trait impl + an `inventory::submit!` registration, so the type
//! joins the global handler registry at link time.
//! - `#[derive(Block)]` does the same for a StreamField block: a
//! `#[block(...)]` attribute plus one `#[field(...)]` per child value.
//!
//! ## Author surface
//!
//! ```ignore
//! use rustango::Model;
//! use rustango_cms::{PageType, PageTypeOverrides};
//!
//! #[derive(Model, PageType, Default, Debug, Clone, serde::Serialize, serde::Deserialize)]
//! #[rustango(table = "blog_post_page_ext", app = "blog")]
//! #[page_type(
//! type_name = "BlogPostPage",
//! verbose_name = "Blog post",
//! template = "blog_post.html",
//! )]
//! pub struct BlogPostPage {
//! #[rustango(primary_key)]
//! pub id: Auto<i64>,
//! #[rustango(fk = "cms_page", on = "id", unique)]
//! pub page_id: i64,
//! #[field(widget = Markdown, label = "Body", help = "GFM.")]
//! pub body_markdown: String,
//! }
//!
//! // ONE additional impl block carries every optional override.
//! impl PageTypeOverrides for BlogPostPage {}
//! ```
//!
//! See `rustango_cms::page_type` for the trait, override trait, and
//! the full surface authors interact with at runtime.
use TokenStream;
/// `#[derive(PageType)]` — generates the `rustango_cms::PageTypeHandler`
/// trait impl from `#[page_type(...)]` and `#[field(...)]` attributes
/// plus a global inventory registration so the type is reachable from
/// `rustango_cms::find_handler(type_name)`.
///
/// See module docs for the author-facing surface.
/// `#[derive(Block)]` — generates the `rustango_cms::Block` trait
/// impl from `#[block(...)]` and `#[field(...)]` attributes plus a
/// global inventory registration so the block joins the registry at
/// link time.
///
/// Author surface:
///
/// ```ignore
/// use rustango_cms::Block;
///
/// #[derive(Default, Block)]
/// #[block(icon = "title", group = "Headings", description = "Section heading.")]
/// pub struct Heading {
/// #[field(widget = Text, required)]
/// pub text: String,
/// #[field(widget = Select, label = "Level", options(h2 = "H2", h3 = "H3"))]
/// pub level: String,
/// }
/// ```
///
/// `type_name` defaults to the snake_case of the struct name;
/// `verbose_name` defaults to the struct name as written. Override
/// either via `#[block(type_name = "…")]` / `#[block(verbose_name = "…")]`.
/// `#[derive(CmsAdmin)]` — an admin editor (list, search, add, edit,
/// delete) for a `#[derive(Model)]` type, at `/cms-admin/x/<slug>`.
/// Fields to edit carry the same `#[field(widget = …, label = "…")]`
/// attributes as page types; the struct needs `Default` and an
/// `impl rustango_cms::CmsAdminOverrides` (empty is fine).