pub struct ComponentDescriptor {
pub id: &'static str,
pub template: &'static str,
pub description: &'static str,
pub category: ComponentCategory,
pub layout_hint: LayoutHint,
}
inventory::collect!(ComponentDescriptor);
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ComponentCategory {
Layout,
TextEditorial,
MetricsKpis,
DataComparison,
NarrativeStorytelling,
Infographics,
MarketingSales,
MediaAssets,
}
impl ComponentCategory {
pub fn label(self) -> &'static str {
match self {
Self::Layout => "Layout",
Self::TextEditorial => "Text & Editorial",
Self::MetricsKpis => "Metrics & KPIs",
Self::DataComparison => "Data & Comparison",
Self::NarrativeStorytelling => "Narrative & Storytelling",
Self::Infographics => "Infographics",
Self::MarketingSales => "Marketing & Sales",
Self::MediaAssets => "Media & Assets",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LayoutHint {
Breakable,
KeepTogether,
AlwaysNewPage,
KeepWithNext,
}
pub struct ComponentCatalog;
impl ComponentCatalog {
pub fn all() -> impl Iterator<Item = &'static ComponentDescriptor> {
inventory::iter::<ComponentDescriptor>()
}
pub fn get(id: &str) -> Option<&'static ComponentDescriptor> {
Self::all().find(|d| d.id == id)
}
pub fn ids() -> Vec<&'static str> {
Self::all().map(|d| d.id).collect()
}
}
#[macro_export]
macro_rules! component_catalog {
(
id: $id:literal,
template: $template:expr,
description: $desc:literal,
category: $cat:expr,
layout_hint: $hint:expr $(,)?
) => {
::inventory::submit! {
$crate::components::catalog::ComponentDescriptor {
id: $id,
template: $template,
description: $desc,
category: $cat,
layout_hint: $hint,
}
}
};
}