diff options
| author | Laurenz <laurmaedje@gmail.com> | 2019-10-23 00:14:43 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2019-10-23 00:21:40 +0200 |
| commit | ecf0ff4d054f11c79ec0ddbbdf45f3dfcf9fc8d7 (patch) | |
| tree | efdc76915e5c7f43629aa3aa5d5aa3998d7f5367 /src/library/align.rs | |
| parent | cff325b520727ac0eec46a3757831afaa0916cc1 (diff) | |
Introduce a set of macros for writing functions more concisely 🎁
Diffstat (limited to 'src/library/align.rs')
| -rw-r--r-- | src/library/align.rs | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/src/library/align.rs b/src/library/align.rs deleted file mode 100644 index cc41f295..00000000 --- a/src/library/align.rs +++ /dev/null @@ -1,49 +0,0 @@ -use super::prelude::*; -use crate::layout::Alignment; - -/// Allows to align content in different ways. -#[derive(Debug, PartialEq)] -pub struct AlignFunc { - alignment: Alignment, - body: Option<SyntaxTree>, -} - -impl Function for AlignFunc { - fn parse(header: &FuncHeader, body: Option<&str>, ctx: ParseContext) -> ParseResult<Self> - where Self: Sized { - if header.args.len() != 1 || !header.kwargs.is_empty() { - return err("align: expected exactly one positional argument"); - } - - let alignment = if let Expression::Ident(ident) = &header.args[0] { - match ident.as_str() { - "left" => Alignment::Left, - "right" => Alignment::Right, - "center" => Alignment::Center, - s => return err(format!("invalid alignment specifier: '{}'", s)), - } - } else { - return err(format!( - "expected alignment specifier, found: '{}'", - header.args[0] - )); - }; - - let body = parse_maybe_body(body, ctx)?; - - Ok(AlignFunc { alignment, body }) - } - - fn layout(&self, ctx: LayoutContext) -> LayoutResult<CommandList> { - if let Some(body) = &self.body { - let layouts = layout_tree(body, LayoutContext { - alignment: self.alignment, - .. ctx - })?; - - Ok(commands![Command::AddMany(layouts)]) - } else { - Ok(commands![Command::SetAlignment(self.alignment)]) - } - } -} |
