add a map for values

This commit is contained in:
annieversary 2022-07-02 14:48:07 +01:00
parent 761af37ba7
commit fa22940ac1
3 changed files with 17 additions and 11 deletions

View File

@ -59,6 +59,7 @@ impl<'a> Class<'a> {
let selector = self.selector(z); let selector = self.selector(z);
if let Some(val) = self.value { if let Some(val) = self.value {
let val = z.values.get(val).map(AsRef::as_ref).unwrap_or(val);
format!("{selector} {{ {name}: {val}; }}",) format!("{selector} {{ {name}: {val}; }}",)
} else if let Some(v) = z.rules.get(name) { } else if let Some(v) = z.rules.get(name) {
format!("{selector} {{ {v} }}",) format!("{selector} {{ {v} }}",)

View File

@ -35,6 +35,16 @@ pub(crate) fn default_names() -> HashMap<String, String> {
.collect() .collect()
} }
pub(crate) fn default_values() -> HashMap<String, String> {
vec![
("full", "100%"),
// TODO
]
.into_iter()
.map(|(a, b)| (a.to_string(), b.to_string()))
.collect()
}
pub(crate) fn default_modifiers() -> HashMap<String, String> { pub(crate) fn default_modifiers() -> HashMap<String, String> {
vec![ vec![
("odd", "nth-child(odd)"), ("odd", "nth-child(odd)"),

View File

@ -2,25 +2,18 @@ use std::collections::HashMap;
use defaults::default_modifiers; use defaults::default_modifiers;
use crate::{ use crate::{defaults::*, parse::*};
defaults::{default_names, default_rules},
parse::*,
};
mod class; mod class;
mod defaults; mod defaults;
mod parse; mod parse;
// pub fn generate_and_write(classes: &[&str], path: impl AsRef<Path>) -> Result<(), std::io::Error> {
// let out = generate_css(classes);
// std::fs::write(path, out)?;
// Ok(())
// }
pub struct Zephyr { pub struct Zephyr {
/// for non-value rules
pub rules: HashMap<String, String>, pub rules: HashMap<String, String>,
pub names: HashMap<String, String>, pub names: HashMap<String, String>,
pub values: HashMap<String, String>,
pub modifiers: HashMap<String, String>, pub modifiers: HashMap<String, String>,
} }
@ -30,6 +23,7 @@ impl Zephyr {
Self { Self {
rules: default_rules(), rules: default_rules(),
names: default_names(), names: default_names(),
values: default_values(),
modifiers: default_modifiers(), modifiers: default_modifiers(),
} }
} }
@ -39,6 +33,7 @@ impl Zephyr {
Self { Self {
rules: HashMap::new(), rules: HashMap::new(),
names: HashMap::new(), names: HashMap::new(),
values: HashMap::new(),
modifiers: HashMap::new(), modifiers: HashMap::new(),
} }
} }