summaryrefslogtreecommitdiff
path: root/src/library/boxed.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-10-17 12:55:34 +0200
committerLaurenz <laurmaedje@gmail.com>2019-10-17 12:55:34 +0200
commit1987e5861cf2c033e3a540a5ef7c0f7106016929 (patch)
treedcbf2d32c88d394e63b60e7473b2f6ba79fc83e3 /src/library/boxed.rs
parentf22f9513aea21408ebf6febd01912e630e9ad5e6 (diff)
Create basic box and line-break functions 📦
Diffstat (limited to 'src/library/boxed.rs')
-rw-r--r--src/library/boxed.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/library/boxed.rs b/src/library/boxed.rs
new file mode 100644
index 00000000..975888f4
--- /dev/null
+++ b/src/library/boxed.rs
@@ -0,0 +1,29 @@
+use super::prelude::*;
+
+/// Wraps content into a box.
+#[derive(Debug, PartialEq)]
+pub struct BoxFunc {
+ body: SyntaxTree
+}
+
+impl Function for BoxFunc {
+ fn parse(header: &FuncHeader, body: Option<&str>, ctx: ParseContext) -> ParseResult<Self>
+ where Self: Sized {
+ if has_arguments(header) {
+ return err("pagebreak: expected no arguments");
+ }
+
+ if let Some(body) = body {
+ Ok(BoxFunc {
+ body: parse(body, ctx)?
+ })
+ } else {
+ err("box: expected body")
+ }
+ }
+
+ fn layout(&self, ctx: LayoutContext) -> LayoutResult<CommandList> {
+ let layout = layout_tree(&self.body, ctx)?;
+ Ok(commands![Command::AddMany(layout)])
+ }
+}