From fa22940ac149e28fd3b0e82024441124159a6f68 Mon Sep 17 00:00:00 2001 From: annieversary Date: Sat, 2 Jul 2022 14:48:07 +0100 Subject: [PATCH] add a map for values --- src/class.rs | 1 + src/defaults.rs | 10 ++++++++++ src/lib.rs | 17 ++++++----------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/class.rs b/src/class.rs index 5a0e875..22cd08c 100644 --- a/src/class.rs +++ b/src/class.rs @@ -59,6 +59,7 @@ impl<'a> Class<'a> { let selector = self.selector(z); if let Some(val) = self.value { + let val = z.values.get(val).map(AsRef::as_ref).unwrap_or(val); format!("{selector} {{ {name}: {val}; }}",) } else if let Some(v) = z.rules.get(name) { format!("{selector} {{ {v} }}",) diff --git a/src/defaults.rs b/src/defaults.rs index 111e66a..733477c 100644 --- a/src/defaults.rs +++ b/src/defaults.rs @@ -35,6 +35,16 @@ pub(crate) fn default_names() -> HashMap { .collect() } +pub(crate) fn default_values() -> HashMap { + vec![ + ("full", "100%"), + // TODO + ] + .into_iter() + .map(|(a, b)| (a.to_string(), b.to_string())) + .collect() +} + pub(crate) fn default_modifiers() -> HashMap { vec![ ("odd", "nth-child(odd)"), diff --git a/src/lib.rs b/src/lib.rs index dc44fa7..e40a8be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,25 +2,18 @@ use std::collections::HashMap; use defaults::default_modifiers; -use crate::{ - defaults::{default_names, default_rules}, - parse::*, -}; +use crate::{defaults::*, parse::*}; mod class; mod defaults; mod parse; -// pub fn generate_and_write(classes: &[&str], path: impl AsRef) -> Result<(), std::io::Error> { -// let out = generate_css(classes); -// std::fs::write(path, out)?; - -// Ok(()) -// } - pub struct Zephyr { + /// for non-value rules pub rules: HashMap, + pub names: HashMap, + pub values: HashMap, pub modifiers: HashMap, } @@ -30,6 +23,7 @@ impl Zephyr { Self { rules: default_rules(), names: default_names(), + values: default_values(), modifiers: default_modifiers(), } } @@ -39,6 +33,7 @@ impl Zephyr { Self { rules: HashMap::new(), names: HashMap::new(), + values: HashMap::new(), modifiers: HashMap::new(), } }