1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use super::*;
#[derive(Clone, Debug)]
enum ColumnKind {
Columns(u8),
Length(LengthUnit),
Standard(String),
}
#[doc = include_str!("readme.md")]
#[derive(Clone, Debug)]
pub struct TailwindColumns {
kind: ColumnKind,
}
impl Display for ColumnKind {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::Columns(n) => write!(f, "{}", n),
Self::Length(n) => write!(f, "{}", n.get_class_arbitrary()),
Self::Standard(g) => write!(f, "{}", g),
}
}
}
impl Display for TailwindColumns {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "columns-{}", self.kind)
}
}
impl TailwindInstance for TailwindColumns {
fn attributes(&self, _: &TailwindBuilder) -> BTreeSet<CssAttribute> {
let columns = match &self.kind {
ColumnKind::Columns(n) => format!("{}", n),
ColumnKind::Length(n) => n.get_properties(),
ColumnKind::Standard(g) => g.to_string(),
};
css_attributes! {
"columns" => columns
}
}
}
impl ColumnKind {
#[inline]
pub fn parse(input: &[&str], arbitrary: &TailwindArbitrary) -> Result<Self> {
let rem = |n: usize| Self::Length(LengthUnit::rem(n as f32));
let out = match input {
["auto"] => Self::Standard("auto".to_string()),
["3xs"] => rem(16),
["2xs"] => rem(18),
["xs"] => rem(20),
["sm"] => rem(24),
["md"] => rem(28),
["lg"] => rem(32),
["xl"] => rem(36),
["2xl"] => rem(42),
["3xl"] => rem(48),
["4xl"] => rem(56),
["5xl"] => rem(64),
["6xl"] => rem(72),
["7xl"] => rem(80),
[name] => {
debug_assert!(!name.contains('%'), "forbidden use percent");
let a = TailwindArbitrary::from(*name);
let maybe_unit = || -> Result<Self> { Ok(Self::Columns(a.as_integer()?)) };
let maybe_length = || -> Result<Self> { Ok(Self::Length(a.as_length()?)) };
maybe_unit().or_else(|_| maybe_length())?
},
[] => Self::Length(arbitrary.as_length()?),
_ => return syntax_error!("Unknown column instructions: {}", input.join("-")),
};
Ok(out)
}
}
impl TailwindColumns {
pub fn parse(input: &[&str], arbitrary: &TailwindArbitrary) -> Result<Self> {
Ok(Self { kind: ColumnKind::parse(input, arbitrary)? })
}
}