Skip to content

Commit

Permalink
feat: add the whitespace plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
arlyon committed Nov 3, 2022
1 parent e420c5d commit 5386680
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
10 changes: 10 additions & 0 deletions crates/tailwind-parse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ mod plugin {
Pointer,
Ease,
Order,
Whitespace(Whitespace),
From,
To,
Outline,
Expand Down Expand Up @@ -101,6 +102,15 @@ mod plugin {
Sr,
}

#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum Whitespace {
Normal,
Nowrap,
Pre,
PreLine,
PreWrap,
}

#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum Gap {
X,
Expand Down
1 change: 1 addition & 0 deletions src/parse/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub fn parse_literal<'a>(theme: &TailwindTheme, lit: Literal<'a>) -> Result<Obje
Flex(f) => return plugin::flex(f, lit.value, theme).ok_or(lit.full),
Grid(g) => return plugin::grid(g, lit.value, theme).ok_or(lit.full),
Object(o) => return plugin::object(o, lit.value, theme).ok_or(lit.full),
Whitespace(ws) => return plugin::white_space(ws, lit.value, theme).ok_or(lit.full),

// all other plugins
Text => Required(plugin::text),
Expand Down
17 changes: 16 additions & 1 deletion src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use swc_core::{
};
use tailwind_parse::{
Border, Display, Flex, Grid, Object, Position, Rounded, TextDecoration, TextTransform,
Visibility,
Visibility, Whitespace,
};

macro_rules! lookup_plugin {
Expand Down Expand Up @@ -525,6 +525,21 @@ pub fn object(o: Object, _rest: Option<SubjectValue>, _theme: &TailwindTheme) ->
Some(to_lit(&rule))
}

pub fn white_space(
o: Whitespace,
_rest: Option<SubjectValue>,
_theme: &TailwindTheme,
) -> Option<ObjectLit> {
let rule = match o {
Whitespace::Normal => [("whiteSpace", "normal")],
Whitespace::Nowrap => [("whiteSpace", "nowrap")],
Whitespace::Pre => [("whiteSpace", "pre")],
Whitespace::PreLine => [("whiteSpace", "pre-line")],
Whitespace::PreWrap => [("whiteSpace", "pre-wrap")],
};
Some(to_lit(&rule))
}

pub fn col(rest: &str, theme: &TailwindTheme) -> Option<ObjectLit> {
simple_lookup(&theme.grid_column, rest, "gridColumn").or_else(|| match rest.split_once('-') {
Some(("start", rest)) => simple_lookup(&theme.grid_column_start, rest, "gridColumnStart"),
Expand Down

0 comments on commit 5386680

Please sign in to comment.