From ecf0ff4d054f11c79ec0ddbbdf45f3dfcf9fc8d7 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 23 Oct 2019 00:14:43 +0200 Subject: =?UTF-8?q?Introduce=20a=20set=20of=20macros=20for=20writing=20fun?= =?UTF-8?q?ctions=20more=20concisely=20=F0=9F=8E=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/library/align.rs | 49 ------------------------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 src/library/align.rs (limited to 'src/library/align.rs') 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, -} - -impl Function for AlignFunc { - fn parse(header: &FuncHeader, body: Option<&str>, ctx: ParseContext) -> ParseResult - 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 { - 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)]) - } - } -} -- cgit v1.2.3