summaryrefslogtreecommitdiff
path: root/library/src/structure
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-11-26 23:42:40 +0100
committerLaurenz <laurmaedje@gmail.com>2022-11-26 23:52:01 +0100
commit6bafc6391061d4b589dea835705a08b25a4df9f8 (patch)
tree4add85f17fc56da341acfb58a223ea20d80c280a /library/src/structure
parent0579fd4409375aaa9fd8e87a06fd59097b5fcd97 (diff)
Document metadata
Diffstat (limited to 'library/src/structure')
-rw-r--r--library/src/structure/doc.rs32
-rw-r--r--library/src/structure/document.rs47
-rw-r--r--library/src/structure/mod.rs4
3 files changed, 49 insertions, 34 deletions
diff --git a/library/src/structure/doc.rs b/library/src/structure/doc.rs
deleted file mode 100644
index e471a852..00000000
--- a/library/src/structure/doc.rs
+++ /dev/null
@@ -1,32 +0,0 @@
-use crate::layout::{LayoutRoot, PageNode};
-use crate::prelude::*;
-
-/// A sequence of page runs.
-#[derive(Hash)]
-pub struct DocNode(pub StyleVec<PageNode>);
-
-#[node(LayoutRoot)]
-impl DocNode {}
-
-impl LayoutRoot for DocNode {
- /// Layout the document into a sequence of frames, one per page.
- fn layout_root(
- &self,
- world: Tracked<dyn World>,
- styles: StyleChain,
- ) -> SourceResult<Vec<Frame>> {
- let mut frames = vec![];
- for (page, map) in self.0.iter() {
- let number = 1 + frames.len();
- frames.extend(page.layout(world, number, styles.chain(map))?);
- }
- Ok(frames)
- }
-}
-
-impl Debug for DocNode {
- fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- f.write_str("Doc ")?;
- self.0.fmt(f)
- }
-}
diff --git a/library/src/structure/document.rs b/library/src/structure/document.rs
new file mode 100644
index 00000000..2e5761e0
--- /dev/null
+++ b/library/src/structure/document.rs
@@ -0,0 +1,47 @@
+use crate::layout::{LayoutRoot, PageNode};
+use crate::prelude::*;
+
+/// The root node of the model.
+#[derive(Hash)]
+pub struct DocumentNode(pub StyleVec<PageNode>);
+
+#[node(LayoutRoot)]
+impl DocumentNode {
+ /// The document's title.
+ #[property(referenced)]
+ pub const TITLE: Option<EcoString> = None;
+
+ /// The document's author.
+ #[property(referenced)]
+ pub const AUTHOR: Option<EcoString> = None;
+}
+
+impl LayoutRoot for DocumentNode {
+ /// Layout the document into a sequence of frames, one per page.
+ fn layout_root(
+ &self,
+ world: Tracked<dyn World>,
+ styles: StyleChain,
+ ) -> SourceResult<Document> {
+ let mut pages = vec![];
+ for (page, map) in self.0.iter() {
+ let number = 1 + pages.len();
+ pages.extend(page.layout(world, number, styles.chain(map))?);
+ }
+
+ Ok(Document {
+ metadata: Metadata {
+ title: styles.get(Self::TITLE).clone(),
+ author: styles.get(Self::AUTHOR).clone(),
+ },
+ pages,
+ })
+ }
+}
+
+impl Debug for DocumentNode {
+ fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+ f.write_str("Document ")?;
+ self.0.fmt(f)
+ }
+}
diff --git a/library/src/structure/mod.rs b/library/src/structure/mod.rs
index 8e13f76a..a1c27eed 100644
--- a/library/src/structure/mod.rs
+++ b/library/src/structure/mod.rs
@@ -1,12 +1,12 @@
//! Document structuring.
-mod doc;
+mod document;
mod heading;
mod list;
mod reference;
mod table;
-pub use self::doc::*;
+pub use self::document::*;
pub use self::heading::*;
pub use self::list::*;
pub use self::reference::*;