From c089d735ea3d734c1d83d8d6c09b5e38d39b0d32 Mon Sep 17 00:00:00 2001 From: theMackabu Date: Mon, 11 Sep 2023 18:32:21 -0700 Subject: [PATCH] support rounded classes --- Cargo.lock | 2 +- Cargo.toml | 2 +- Maidfile.toml | 2 +- src/css.rs | 5 ++++- src/util.rs | 11 +++++++++-- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 304984a..66df93e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -481,7 +481,7 @@ dependencies = [ [[package]] name = "mkcss" -version = "0.1.6" +version = "0.2.0" dependencies = [ "clap", "clap-verbosity-flag", diff --git a/Cargo.toml b/Cargo.toml index 8f4e646..8d0c8b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mkcss" -version = "0.1.7" +version = "0.2.0" edition = "2021" license = "MIT" repository = "https://github.com/exact-rs/mkcss" diff --git a/Maidfile.toml b/Maidfile.toml index ca35a6e..9cef377 100644 --- a/Maidfile.toml +++ b/Maidfile.toml @@ -2,7 +2,7 @@ import = ["util/convert.toml"] [project] name = "mkcss" -version = "0.1.7" +version = "0.2.0" [tasks.build] info = "Build binaries" diff --git a/src/css.rs b/src/css.rs index 1654058..5222dd2 100644 --- a/src/css.rs +++ b/src/css.rs @@ -43,16 +43,19 @@ pub fn create_stylesheet(classes: Vec<&String>, add_reset: bool) -> String { } "fg" => css_content.push_str(&format!(".{} {{ color: #{} !important }}\n", class, parts.get(1).unwrap_or(&""))), "bg" => css_content.push_str(&format!(".{} {{ background-color: #{} !important }}\n", class, parts.get(1).unwrap_or(&""))), + "bc" => css_content.push_str(&format!(".{} {{ border-color: #{} !important }}\n", class, parts.get(1).unwrap_or(&""))), _ => { let property_value = parts .get(if class.starts_with("-") { 2 } else { 1 }) .map(|&s| if class.starts_with("-") { format!("-{}", s) } else { s.to_string() }) .unwrap_or_else(String::new); - if let Some(&(_, property)) = util::MARGIN_STYLES.iter().find(|(prop_name, _)| prop_name == &name) { + if let Some(&(_, property)) = util::CONTROL_STYLES.iter().find(|(prop_name, _)| prop_name == &name) { let sign = if name.starts_with("-") { "-" } else { "" }; let declarations: Vec = property.split_whitespace().map(|p| format!("{}: {}{}px !important", p, sign, property_value)).collect(); css_content.push_str(&format!(".{} {{ {} }}\n", class, declarations.join("; "))); + } else if let Some(&(_, value)) = util::STYLES.iter().find(|(key, _)| key == *&class) { + css_content.push_str(&format!(".{} {{ {} }}\n", class, value)); } } } diff --git a/src/util.rs b/src/util.rs index 836044c..562b0d8 100644 --- a/src/util.rs +++ b/src/util.rs @@ -212,11 +212,11 @@ pub const STYLES: [(&str, &str); 273] = [ ("rounded-bl-2xl", "border-bottom-left-radius: 1rem"), ("rounded-bl-3xl", "border-bottom-left-radius: 1.5rem"), ("rounded-bl-full", "border-bottom-left-radius: 9999px"), + ("border", "border-style: solid; border-width: 1px"), ("border-0", "border-width: 0px"), ("border-2", "border-width: 2px"), ("border-4", "border-width: 4px"), ("border-8", "border-width: 8px"), - ("border", "border-width: 1px"), ("border-x-0", "border-left-width: 0px"), ("border-right-width:", "0px"), ("border-x-2", "border-left-width: 2px"), @@ -278,7 +278,7 @@ pub const STYLES: [(&str, &str); 273] = [ ("font-mono", MONO), ]; -pub const MARGIN_STYLES: [(&str, &str); 7] = [ +pub const CONTROL_STYLES: [(&str, &str); 14] = [ ("m", "margin"), ("mt", "margin-top"), ("mr", "margin-right"), @@ -286,4 +286,11 @@ pub const MARGIN_STYLES: [(&str, &str); 7] = [ ("ml", "margin-left"), ("mx", "margin-left margin-right"), ("my", "margin-top margin-bottom"), + ("p", "padding"), + ("pt", "padding-top"), + ("pr", "padding-right"), + ("pb", "padding-bottom"), + ("pl", "padding-left"), + ("px", "padding-left padding-right"), + ("py", "padding-top padding-bottom"), ]; -- GitLab