From 28d7886ee8752cdace3ad422389d5e9fc73b2c26 Mon Sep 17 00:00:00 2001 From: annieversary Date: Sat, 2 Jul 2022 14:58:57 +0100 Subject: [PATCH] add map for pseudo elements --- src/class.rs | 3 ++- src/defaults.rs | 10 ++++++++++ src/lib.rs | 3 +++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/class.rs b/src/class.rs index 22cd08c..5698baf 100644 --- a/src/class.rs +++ b/src/class.rs @@ -28,12 +28,13 @@ impl<'a> Class<'a> { if let Some(pseudo) = pseudo { rest.push_str("::"); + let pseudo: &str = z.pseudos.get(*pseudo).map(AsRef::as_ref).unwrap_or(pseudo); rest.push_str(pseudo); } // TODO we can probably skip the format here, we just need to push the char at the start if !rest.is_empty() { - rest = format!(":{rest}"); + rest.insert(0, ':') } format!(".{original}{rest}") diff --git a/src/defaults.rs b/src/defaults.rs index 733477c..47d73fe 100644 --- a/src/defaults.rs +++ b/src/defaults.rs @@ -58,3 +58,13 @@ pub(crate) fn default_modifiers() -> HashMap { .map(|(a, b)| (a.to_string(), b.to_string())) .collect() } + +pub(crate) fn default_pseudos() -> HashMap { + vec![ + ("ph", "placeholder"), + // TODO + ] + .into_iter() + .map(|(a, b)| (a.to_string(), b.to_string())) + .collect() +} diff --git a/src/lib.rs b/src/lib.rs index e40a8be..310537e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,6 +15,7 @@ pub struct Zephyr { pub names: HashMap, pub values: HashMap, pub modifiers: HashMap, + pub pseudos: HashMap, } impl Zephyr { @@ -25,6 +26,7 @@ impl Zephyr { names: default_names(), values: default_values(), modifiers: default_modifiers(), + pseudos: default_pseudos(), } } @@ -35,6 +37,7 @@ impl Zephyr { names: HashMap::new(), values: HashMap::new(), modifiers: HashMap::new(), + pseudos: HashMap::new(), } }