tailwind_css_fixes/traits/
mod.rs1use std::{
2 cmp::Ordering,
3 fmt::{Debug, Display, Formatter},
4 hash::{Hash, Hasher},
5};
6
7use crate::{CssAttributes, TailwindBuilder};
8
9pub mod instance;
10
11#[allow(unused_variables)]
12pub trait TailwindInstance: Display {
13 #[inline]
15 fn id(&self) -> String {
16 normalize_class_name(&self.to_string())
17 }
18 fn inlineable(&self) -> bool {
20 true
21 }
22 fn boxed(self) -> Box<dyn TailwindInstance>
24 where
25 Self: Sized,
26 Self: 'static,
27 {
28 Box::new(self)
29 }
30 fn selectors(&self, ctx: &TailwindBuilder) -> String {
32 format!(".{}", self.id())
33 }
34 fn attributes(&self, ctx: &TailwindBuilder) -> CssAttributes;
36 fn additional(&self, ctx: &TailwindBuilder) -> String {
38 String::new()
39 }
40}
41
42fn normalize_class_name(name: &str) -> String {
44 let mut out = String::new();
45 for c in name.chars() {
46 match c {
47 ' ' => out.push('_'),
48 r @ ('-' | '_') => out.push(r),
49 a if a.is_alphanumeric() => out.push(a),
50 _ => out.push(c),
51 }
52 }
53 out
54}