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_html_class_name(&self.to_string())
17 }
18 fn inlineable(&self) -> bool {
21 true
22 }
23 fn boxed(self) -> Box<dyn TailwindInstance>
25 where
26 Self: Sized,
27 Self: 'static,
28 {
29 Box::new(self)
30 }
31 fn selectors(&self, ctx: &TailwindBuilder) -> String {
33 format!(".{}", self.id())
34 }
35 fn attributes(&self, ctx: &TailwindBuilder) -> CssAttributes;
37 fn additional(&self, ctx: &TailwindBuilder) -> String {
39 String::new()
40 }
41}
42
43fn normalize_html_class_name(name: &str) -> String {
49 let mut out = String::new();
50 for c in name.chars() {
51 match c {
52 ' ' => out.push('_'),
53 r @ ('-' | '_') => out.push(r),
54 a if a.is_alphanumeric() => out.push(a),
55 _ => out.push(c),
56 }
57 }
58 out
59}