tailwind_css_fixes/systems/units/keyword_only/
mod.rs1use super::*;
2
3mod traits;
4
5#[derive(Debug, Clone)]
7pub enum StandardValue {
8 Keyword(String),
9 Arbitrary(TailwindArbitrary),
10}
11
12impl StandardValue {
13 pub fn parser(
14 id: &'static str,
15 check_valid: &'static impl Fn(&str) -> bool,
16 ) -> impl Fn(&[&str], &TailwindArbitrary) -> Result<Self> {
17 move |pattern: &[&str], arbitrary: &TailwindArbitrary| match pattern {
18 [] => Self::parse_arbitrary(arbitrary),
19 _ => Self::parse_keyword(pattern, id, check_valid),
20 }
21 }
22 pub fn parse_arbitrary(arbitrary: &TailwindArbitrary) -> Result<Self> {
23 Ok(Self::Arbitrary(TailwindArbitrary::new(arbitrary)?))
24 }
25 pub fn parse_keyword(pattern: &[&str], id: &str, checker: &'static impl Fn(&str) -> bool) -> Result<Self> {
26 let keyword = pattern.join("-");
27 if cfg!(compile_time) && !checker(&keyword) {
28 return syntax_error!("{} does not a valid value of {}", keyword, id);
29 }
30 Ok(Self::Keyword(keyword))
31 }
32 pub fn get_properties(&self) -> &str {
33 match self {
34 Self::Keyword(s) => s.as_str(),
35 Self::Arbitrary(s) => s.as_str(),
36 }
37 }
38 pub fn get_value(&self) -> &str {
39 match self {
40 Self::Keyword(s) => s.as_str(),
41 Self::Arbitrary(s) => s.as_str(),
42 }
43 }
44 pub fn write_class(
45 &self,
46 fmt: &mut Formatter,
47 class: &str,
48 special: fn(&mut Formatter, &str) -> std::fmt::Result,
49 ) -> std::fmt::Result {
50 match self {
51 StandardValue::Keyword(s) => match special(fmt, s) {
52 Ok(o) => Ok(o),
53 Err(_) => write!(fmt, "{}", class),
54 },
55 StandardValue::Arbitrary(s) => s.write_class(fmt, class),
56 }
57 }
58}