Skip to main content

quillmark_core/
quill.rs

1//! Quill source bundle types and implementations.
2
3mod blueprint;
4mod config;
5mod fill;
6mod formats;
7mod ignore;
8mod load;
9mod query;
10mod schema;
11mod schema_yaml;
12mod tree;
13mod types;
14pub(crate) mod validation;
15
16pub use config::{CoercionError, QuillConfig};
17pub use fill::zero_value;
18pub use ignore::QuillIgnore;
19pub use schema::build_transform_schema;
20pub use tree::FileTreeNode;
21pub use types::{
22    field_key, ui_key, BodyCardSchema, CardSchema, FieldSchema, FieldType, UiCardSchema,
23    UiFieldSchema,
24};
25
26use std::collections::HashMap;
27
28use crate::value::QuillValue;
29
30/// A quill source bundle — pure data parsed from an authored quill directory.
31///
32/// A `QuillSource` is the file-bundle, config, and metadata; it has no rendering
33/// ability. The engine composes a `QuillSource` with a resolved backend into a
34/// renderable `Quill` (see `quillmark::Quill`).
35#[derive(Clone)]
36pub struct QuillSource {
37    pub(crate) metadata: HashMap<String, QuillValue>,
38    pub(crate) plate: Option<String>,
39    pub(crate) config: QuillConfig,
40    pub(crate) files: FileTreeNode,
41}
42
43impl QuillSource {
44    /// The quill's declared name.
45    pub fn name(&self) -> &str {
46        &self.config.name
47    }
48
49    /// The backend identifier declared in Quill.yaml (e.g. `"typst"`).
50    pub fn backend_id(&self) -> &str {
51        &self.config.backend
52    }
53
54    /// Quill-specific metadata parsed from Quill.yaml.
55    pub fn metadata(&self) -> &HashMap<String, QuillValue> {
56        &self.metadata
57    }
58
59    /// The plate template content, if the quill declares one.
60    pub fn plate(&self) -> Option<&str> {
61        self.plate.as_deref()
62    }
63
64    /// The parsed schema configuration.
65    pub fn config(&self) -> &QuillConfig {
66        &self.config
67    }
68
69    /// The in-memory file tree for this quill.
70    pub fn files(&self) -> &FileTreeNode {
71        &self.files
72    }
73}
74
75impl std::fmt::Debug for QuillSource {
76    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
77        f.debug_struct("QuillSource")
78            .field("name", &self.config.name)
79            .field("backend_id", &self.config.backend)
80            .field(
81                "plate",
82                &self.plate.as_ref().map(|s| format!("<{} bytes>", s.len())),
83            )
84            .field("files", &"<FileTreeNode>")
85            .finish()
86    }
87}
88
89#[cfg(test)]
90mod tests;