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
use super::*;
pub(crate) mod grid_auto;
pub(crate) mod grid_cols;
pub(crate) mod grid_flow;
pub(crate) mod grid_rows;
#[doc=include_str!("readme.md")]
#[derive(Debug, Clone, Copy)]
pub struct TailwindGrid {}
impl TailwindGrid {
pub fn adapt(str: &[&str], arbitrary: &TailwindArbitrary) -> Result<Box<dyn TailwindInstance>> {
let out = match str {
["rows", rest @ ..] => TailwindGridRows::parse(rest, arbitrary)?.boxed(),
["cols", rest @ ..] => TailwindGridColumns::parse(rest, arbitrary)?.boxed(),
["flow", rest @ ..] => TailwindGridFlow::parse(rest, arbitrary)?.boxed(),
_ => return syntax_error!("Unknown list instructions: {}", str.join("-")),
};
Ok(out)
}
}
#[derive(Debug, Clone)]
enum GridTemplate {
None,
Unit(i32),
Arbitrary(TailwindArbitrary),
}
impl Display for GridTemplate {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
GridTemplate::None => write!(f, "none"),
GridTemplate::Unit(s) => write!(f, "{}", s),
GridTemplate::Arbitrary(s) => s.write(f),
}
}
}
impl GridTemplate {
pub fn parse(pattern: &[&str], arbitrary: &TailwindArbitrary) -> Result<Self> {
let kind = match pattern {
["none"] => Self::None,
[n] => Self::Unit(TailwindArbitrary::from(*n).as_integer()?),
_ => Self::parse_arbitrary(arbitrary)?,
};
Ok(kind)
}
pub fn parse_arbitrary(arbitrary: &TailwindArbitrary) -> Result<Self> {
Ok(Self::Arbitrary(TailwindArbitrary::new(arbitrary)?))
}
pub fn get_properties(&self) -> String {
match self {
GridTemplate::None => "none".to_string(),
GridTemplate::Unit(s) => format!("repeat({},minmax(0,1fr))", s),
GridTemplate::Arbitrary(s) => s.get_properties(),
}
}
}