Skip to main content

Crate rustango_cms_macros

Crate rustango_cms_macros 

Source
Expand description

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

ⓘ
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.

Derive Macros§

Block
#[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.
CmsAdmin
#[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).
PageType
#[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).