use indexmap::IndexMap;
#[derive(Debug, Clone)]
pub struct WdocDocument {
pub name: String,
pub title: String,
pub template: WdocTemplate,
pub version: Option<String>,
pub author: Option<String>,
pub site: SiteConfig,
pub sections: Vec<Section>,
pub pages: Vec<Page>,
pub styles: Vec<WdocStyle>,
pub extra_css: String,
}
#[derive(Debug, Clone)]
pub struct Section {
pub id: String,
pub short_id: String,
pub title: String,
pub children: Vec<Section>,
}
#[derive(Debug, Clone)]
pub struct Page {
pub id: String,
pub section_id: String,
pub title: String,
pub template: Option<WdocTemplate>,
pub path: Option<String>,
pub date: Option<String>,
pub draft: bool,
pub weight: Option<i64>,
pub summary: Option<String>,
pub tags: Vec<String>,
pub categories: Vec<String>,
pub params: IndexMap<String, String>,
pub layout: Layout,
pub signals: Vec<WdocSignal>,
pub bindings: Vec<WdocBinding>,
}
#[derive(Debug, Clone, Default)]
pub struct SiteConfig {
pub header_html: Option<String>,
pub nav_html: Option<String>,
pub footer_html: Option<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WdocTemplate {
Book,
Site,
Presentation,
}
impl WdocTemplate {
pub const DEFAULT: Self = Self::Book;
pub fn parse(value: &str) -> Result<Self, String> {
match value {
"book" => Ok(Self::Book),
"site" => Ok(Self::Site),
"presentation" => Ok(Self::Presentation),
other => Err(format!(
"unknown wdoc template '{other}' (supported: book, site, presentation)"
)),
}
}
pub fn as_str(self) -> &'static str {
match self {
Self::Book => "book",
Self::Site => "site",
Self::Presentation => "presentation",
}
}
}
#[derive(Debug, Clone)]
pub struct Layout {
pub children: Vec<LayoutItem>,
}
#[derive(Debug, Clone)]
pub enum LayoutItem {
SplitGroup(SplitGroup),
Content(ContentBlock),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SplitDirection {
Vertical,
Horizontal,
}
#[derive(Debug, Clone)]
pub struct SplitGroup {
pub direction: SplitDirection,
pub splits: Vec<Split>,
}
#[derive(Debug, Clone)]
pub struct Split {
pub size_percent: f64,
pub children: Vec<LayoutItem>,
}
#[derive(Debug, Clone)]
pub struct ContentBlock {
pub kind: String,
pub id: Option<String>,
pub rendered_html: String,
pub style: Option<String>,
}
#[derive(Debug, Clone)]
pub struct WdocSignal {
pub name: String,
pub initial: serde_json::Value,
pub type_name: Option<String>,
}
#[derive(Debug, Clone)]
pub struct WdocBinding {
pub name: Option<String>,
pub signal: String,
pub target: String,
pub property: String,
pub path: Option<String>,
pub format: Option<String>,
}
#[derive(Debug, Clone)]
pub struct WdocStyle {
pub name: String,
pub rules: Vec<StyleRule>,
}
#[derive(Debug, Clone)]
pub struct StyleRule {
pub target: String,
pub properties: IndexMap<String, String>,
}