From 41b4d60bbb86e563e0ea3e1b158b7fac1c293414 Mon Sep 17 00:00:00 2001 From: Alexander Lyon Date: Mon, 20 Feb 2023 17:38:05 +0000 Subject: [PATCH] feat: support content subcommands --- crates/tailwind-parse/src/eval/plugin.rs | 26 ++++++++++++++++++++++-- crates/tailwind-parse/src/literal.rs | 2 +- crates/tailwind-parse/src/plugin.rs | 14 ++++++++++++- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/crates/tailwind-parse/src/eval/plugin.rs b/crates/tailwind-parse/src/eval/plugin.rs index ff5ea4e..4c8e094 100644 --- a/crates/tailwind-parse/src/eval/plugin.rs +++ b/crates/tailwind-parse/src/eval/plugin.rs @@ -825,8 +825,30 @@ pub fn row<'a>(row: Option, value: &Value, theme: &'a TailwindTheme) -> Plu } } -pub fn content<'a>(rest: &SubjectValue, _theme: &'a TailwindTheme) -> PluginResult<'a> { - Ok(to_lit(&[("content", rest.as_str())])) +pub fn content<'a>( + c: Option, + rest: &Option, + _theme: &'a TailwindTheme, +) -> PluginResult<'a> { + let rule = match c { + None | Some(Content::None) => "content", + _ => "alignContent", + }; + + let value = match (c, rest) { + (None, Some(rest)) => rest.as_str(), + (Some(Content::None), None) => "none", + (Some(Content::Around), None) => "space-around", + (Some(Content::Between), None) => "space-between", + (Some(Content::Center), None) => "center", + (Some(Content::End), None) => "flex-end", + (Some(Content::Evenly), None) => "space-evenly", + (Some(Content::Start), None) => "flex-start", + (Some(Content::Baseline), None) => "baseline", + _ => return Err(vec![]), + }; + + Ok(to_lit(&[(rule, value)])) } array_map_plugin!( diff --git a/crates/tailwind-parse/src/literal.rs b/crates/tailwind-parse/src/literal.rs index b35f3d8..0c20c22 100644 --- a/crates/tailwind-parse/src/literal.rs +++ b/crates/tailwind-parse/src/literal.rs @@ -123,6 +123,7 @@ impl<'a> Literal<'a> { Backdrop(b) => OptionalAbitraryBox(StdBox::new(move |v, t| plugin::backdrop(b, v, t))), Snap(s) => OptionalAbitraryBox(StdBox::new(move |v, t| plugin::snap(s, v, t))), Scroll(s) => OptionalAbitraryBox(StdBox::new(move |v, t| plugin::scroll(s, v, t))), + Content(c) => OptionalAbitraryBox(StdBox::new(move |v, t| plugin::content(c, v, t))), Auto(Auto::Cols) => Required(plugin::auto_cols), Auto(Auto::Rows) => Required(plugin::auto_rows), @@ -146,7 +147,6 @@ impl<'a> Literal<'a> { Aspect => RequiredArbitrary(plugin::aspect), Outline => OptionalArbitrary(plugin::outline), Mix => Required(plugin::mix), - Content => RequiredArbitrary(plugin::content), Grow => Optional(plugin::grow), Shrink => Optional(plugin::shrink), Basis => Required(plugin::basis), diff --git a/crates/tailwind-parse/src/plugin.rs b/crates/tailwind-parse/src/plugin.rs index bac8c50..81b1acc 100644 --- a/crates/tailwind-parse/src/plugin.rs +++ b/crates/tailwind-parse/src/plugin.rs @@ -58,7 +58,7 @@ mod plugin { #[rename("align")] VerticalAlign, Pb, - Content, + Content(Option), M, Mx, My, @@ -353,6 +353,18 @@ mod plugin { Hidden, } + #[derive(Copy, Clone, Eq, PartialEq, Debug)] + pub enum Content { + None, + Center, + Start, + End, + Between, + Around, + Evenly, + Baseline, + } + #[derive(Copy, Clone, Eq, PartialEq, Debug)] pub enum TextTransform { Uppercase,