Skip to content

Commit

Permalink
feat: make col plugin support arbitrary CSS
Browse files Browse the repository at this point in the history
  • Loading branch information
arlyon committed Feb 20, 2023
1 parent dd7656b commit c3d7b19
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion crates/tailwind-parse/src/eval/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,11 @@ pub fn white_space(
Ok(to_lit(&rule))
}

pub fn col<'a>(col: Option<Col>, value: &Value, theme: &'a TailwindTheme) -> PluginResult<'a> {
pub fn col<'a>(
col: Option<Col>,
value: &SubjectValue,
theme: &'a TailwindTheme,
) -> PluginResult<'a> {
match col {
None => grid_col(value, theme),
Some(Col::Start) => grid_col_start(value, theme),
Expand Down
6 changes: 4 additions & 2 deletions crates/tailwind-parse/src/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ enum PluginType<'a> {
Optional(fn(Option<&Value>, &'a TailwindTheme) -> PluginResult<'a>),
/// This plugin requires a value, or arbitrary css.
RequiredArbitrary(fn(&SubjectValue, &'a TailwindTheme) -> PluginResult<'a>),
RequiredArbitraryBox(Box<dyn Fn(&SubjectValue, &'a TailwindTheme) -> PluginResult<'a>>),
/// This plugin takes an optional value, or arbitrary css.
OptionalArbitrary(fn(&Option<SubjectValue>, &'a TailwindTheme) -> PluginResult<'a>),
OptionalArbitrary(fn(Option<&SubjectValue>, &'a TailwindTheme) -> PluginResult<'a>),
}

impl<'a> Literal<'a> {
Expand Down Expand Up @@ -107,7 +108,7 @@ impl<'a> Literal<'a> {
Translate(tr) => {
OptionalAbitraryBox(StdBox::new(move |v, t| plugin::translate(tr, v, t)))
}
Col(c) => RequiredBox(StdBox::new(move |v, t| plugin::col(c, v, t))),
Col(c) => RequiredArbitraryBox(StdBox::new(move |v, t| plugin::col(c, v, t))),
Row(r) => RequiredBox(StdBox::new(move |v, t| plugin::row(r, v, t))),
Overflow(o) => RequiredBox(StdBox::new(move |v, t| plugin::overflow(o, v, t))),
Not(_) => todo!(),
Expand Down Expand Up @@ -213,6 +214,7 @@ impl<'a> Literal<'a> {
(Optional(p), Some(SubjectValue::Value(s))) => p(Some(s), theme),
(Optional(p), None) => p(None, theme),
(RequiredArbitrary(p), Some(value)) => p(value, theme),
(RequiredArbitraryBox(p), Some(value)) => p(value, theme),
(Singular(p), None) => Ok(p()),
(RequiredBox(p), Some(SubjectValue::Value(value))) => p(value, theme),
(OptionalAbitraryBox(p), value) => p(value, theme),
Expand Down

0 comments on commit c3d7b19

Please sign in to comment.