From 3110f1d0e01d904e290380ce2e3ded3d3ffe3a1f Mon Sep 17 00:00:00 2001 From: oyelowo Date: Fri, 17 Jan 2025 16:49:40 +0200 Subject: [PATCH 01/11] Remove unnecessary conversion --- twust-macro/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twust-macro/src/lib.rs b/twust-macro/src/lib.rs index 561d969..5574795 100644 --- a/twust-macro/src/lib.rs +++ b/twust-macro/src/lib.rs @@ -77,7 +77,7 @@ fn is_valid_modifier(modifier: &str) -> bool { let modifiers: HashSet = HashSet::from_iter(get_modifiers( &read_tailwind_config().expect("Problem getting modifiers"), )); - modifiers.contains(&modifier.to_string()) + modifiers.contains(modifier) } fn parse_predefined_tw_classname(input: &str) -> IResult<&str, ()> { From 08aba7bb3bdba589d8a16b867370acac5e1e1241 Mon Sep 17 00:00:00 2001 From: oyelowo Date: Fri, 17 Jan 2025 19:35:54 +0200 Subject: [PATCH 02/11] Update error message --- twust-macro/src/config/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twust-macro/src/config/mod.rs b/twust-macro/src/config/mod.rs index 847b89b..54a4f91 100644 --- a/twust-macro/src/config/mod.rs +++ b/twust-macro/src/config/mod.rs @@ -71,7 +71,7 @@ pub(crate) fn read_tailwind_config() -> Result { return Err(std::io::Error::new( std::io::ErrorKind::NotFound, format!( - "tailwind.config.json was not found in the top-level directory - \n{config_path:?}. Ensure it exists." + "tailwind.config.json was not found in the top-level directory - \n{config_path:?}. Make sure it exists." ), )); } From 6007eb6b50643ecd7f7a3a5278a994cd5f08bd54 Mon Sep 17 00:00:00 2001 From: oyelowo Date: Fri, 17 Jan 2025 19:36:12 +0200 Subject: [PATCH 03/11] Add wildcard to default modifiers --- twust-macro/src/tailwind/modifiers.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/twust-macro/src/tailwind/modifiers.rs b/twust-macro/src/tailwind/modifiers.rs index 724cd53..0777fa1 100644 --- a/twust-macro/src/tailwind/modifiers.rs +++ b/twust-macro/src/tailwind/modifiers.rs @@ -82,7 +82,8 @@ use crate::config::{add_classes_for_field, modifiers}; use super::tailwind_config::TailwindConfig; -const MODIFIERS: [&str; 49] = [ +const MODIFIERS: [&str; 50] = [ + "*", "hover", "focus", "focus-within", @@ -160,7 +161,7 @@ pub fn get_modifiers(config: &TailwindConfig) -> Vec { // "max-[…]", ] .into_iter() - .map(|x| x.to_string()) + .map(Into::into) .collect::>(); if let Some(ref screens) = config.theme.overrides.screens { From d1f7c8985ed6cb10b17051f9c0749d4275fe4581 Mon Sep 17 00:00:00 2001 From: oyelowo Date: Fri, 17 Jan 2025 19:36:37 +0200 Subject: [PATCH 04/11] Support group-data arbitrary and wildcard modifiers --- twust-macro/src/lib.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/twust-macro/src/lib.rs b/twust-macro/src/lib.rs index 5574795..cd9cb5d 100644 --- a/twust-macro/src/lib.rs +++ b/twust-macro/src/lib.rs @@ -70,7 +70,7 @@ fn get_classes_straight() -> HashSet { } fn is_valid_classname(class_name: &str) -> bool { - get_classes_straight().contains(&class_name.to_string()) + get_classes_straight().contains(class_name) } fn is_valid_modifier(modifier: &str) -> bool { @@ -616,13 +616,16 @@ fn supports_arbitrary(input: &str) -> IResult<&str, ()> { // aria-[sort=ascending]:bg-[url('/img/down-arrow.svg')] // aria-[sort=descending]:bg-[url('/img/up-arrow.svg')] -fn aria_arbitrary(input: &str) -> IResult<&str, ()> { +// group-data-[selected=Right]:w-[30px] +// group-aria-[main-page=false]/main:hidden / group-data-[main-page=false]/main:hidden +fn aria_or_data_arbitrary(input: &str) -> IResult<&str, ()> { let (input, _) = opt(tag("group-"))(input)?; - let (input, _) = tag("aria-[")(input)?; + let (input, _) = alt((tag("aria-["), tag("data-[")))(input)?; let (input, _) = take_while1(is_ident_char)(input)?; let (input, _) = tag("=")(input)?; let (input, _) = take_while1(is_ident_char)(input)?; let (input, _) = tag("]")(input)?; + let (input, _) = opt(tuple((tag("/"), take_while1(is_ident_char))))(input)?; Ok((input, ())) } @@ -645,6 +648,12 @@ fn min_max_arbitrary_modifier(input: &str) -> IResult<&str, ()> { Ok((input, ())) } +// *:overflow-scroll +fn wildcard_modifier(input: &str) -> IResult<&str, ()> { + let (input, _) = tag("*")(input)?; + Ok((input, ())) +} + fn modifier(input: &str) -> IResult<&str, ()> { alt(( group_modifier_selector, @@ -656,9 +665,10 @@ fn modifier(input: &str) -> IResult<&str, ()> { arbitrary_at_media_rule_modifier, predefined_modifier, supports_arbitrary, - aria_arbitrary, + aria_or_data_arbitrary, data_arbitrary, min_max_arbitrary_modifier, + wildcard_modifier, ))(input) } @@ -723,6 +733,11 @@ fn parse_top(input: &str) -> IResult<&str, Vec<&str>> { all_consuming(parse_class_names)(input) } +#[test] +fn test_group_attr_arbitrary2() { + assert_eq!(parse_top("group-data-[selected=Right]"), Ok(("", vec![]))); +} + #[proc_macro] pub fn tw(raw_input: TokenStream) -> TokenStream { let r_input = raw_input.clone(); From bb9ef4c044d446efb5659b20178bb8807a96d001 Mon Sep 17 00:00:00 2001 From: oyelowo Date: Fri, 17 Jan 2025 19:39:50 +0200 Subject: [PATCH 05/11] Support new cases --- tailwind/src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tailwind/src/lib.rs b/tailwind/src/lib.rs index 3b6191b..e8a078e 100644 --- a/tailwind/src/lib.rs +++ b/tailwind/src/lib.rs @@ -117,6 +117,11 @@ fn _invalid_group_usage_3() {} fn _happy_paths() { fn main() { + let _classnames = tw!("group-data-[selected=Right]:w-[30px]"); + let _classnames = tw!("group-aria-[main-page=false]/main:hidden"); + let _classnames = tw!("group-data-[main-page=false]/main:hidden"); + let _classnames = tw!("*:overflow-scroll"); + let _classnames = tw!("bg-taxvhiti bg-tahiti-500 bg-tahiti bg-midnight bg-red-50"); let _classnames = tw!("bg-taxvhiti bg-tahiti-500 bg-tahiti bg-midnight bg-purple bg-red-50 bg-tahiti-800 border-s-tahiti-800"); let _classnames = tw!("md:text-red-50 text-slate-50 text-purple text-tahiti-500"); From bccccf84883d5a7dc5243074b06180d487aac5db Mon Sep 17 00:00:00 2001 From: oyelowo Date: Fri, 17 Jan 2025 20:19:56 +0200 Subject: [PATCH 06/11] Upddate packages --- examples/leptos-demo/Cargo.toml | 10 +++++----- examples/leptos-demo/Makefile.toml | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/leptos-demo/Cargo.toml b/examples/leptos-demo/Cargo.toml index 80ceca3..395bbbd 100644 --- a/examples/leptos-demo/Cargo.toml +++ b/examples/leptos-demo/Cargo.toml @@ -6,11 +6,11 @@ edition = "2021" [workspace] [dependencies] -leptos = { version = "0.5.0-beta2", features = ["csr", "nightly"] } -leptos_meta = { version = "0.5.0-beta2", features = ["csr", "nightly"] } -leptos_router = { version = "0.5.0-beta2", features = ["csr", "nightly"] } -log = "0.4.2" -gloo-net = { version = "0.4.0", features = ["http"] } +leptos = { version = "0.7.4", features = ["csr"] } +leptos_meta = { version = "0.7.4" } +leptos_router = { version = "0.7.4" } +log = "0.4.25" +gloo-net = { version = "0.6.0", features = ["http"] } twust = { version = "*", features = ["daisyui"] } # twust = { git = "https://github.com/oyelowo/twust", features = ["daisyui"] } diff --git a/examples/leptos-demo/Makefile.toml b/examples/leptos-demo/Makefile.toml index 6fe5328..3faa972 100644 --- a/examples/leptos-demo/Makefile.toml +++ b/examples/leptos-demo/Makefile.toml @@ -1 +1,3 @@ extend = [{ path = "../cargo-make/main.toml" }] + + From fa8d30b6731cb5e55625389411fcaf578270ee41 Mon Sep 17 00:00:00 2001 From: oyelowo Date: Fri, 17 Jan 2025 20:20:00 +0200 Subject: [PATCH 07/11] Update example --- examples/leptos-demo/src/app.rs | 23 +++-------------------- examples/leptos-demo/src/main.rs | 16 +++++++++------- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/examples/leptos-demo/src/app.rs b/examples/leptos-demo/src/app.rs index 52b47e0..bdbda95 100644 --- a/examples/leptos-demo/src/app.rs +++ b/examples/leptos-demo/src/app.rs @@ -1,28 +1,11 @@ -use leptos::*; -use leptos_meta::*; -use leptos_router::*; +use leptos::prelude::*; use twust::tw; #[component] -pub fn App() -> impl IntoView { - provide_meta_context(); - - view! { - - - - - }/> - - - } -} - -#[component] -fn Home() -> impl IntoView { +pub fn Home() -> impl IntoView { // Try to break mistype any of the class name and see what happens. // Daisyui classes are also ssupported via a feature flag - let x = tw!("my-5 mx-auto max-w-3xl text-center"); + let _x = tw!("my-5 mx-auto max-w-3xl text-center"); view! {

"Twust"

diff --git a/examples/leptos-demo/src/main.rs b/examples/leptos-demo/src/main.rs index bf35e89..2a952e5 100644 --- a/examples/leptos-demo/src/main.rs +++ b/examples/leptos-demo/src/main.rs @@ -3,13 +3,15 @@ mod app; use app::*; use leptos::*; +use leptos_router::components::Router; + pub fn main() { - _ = console_log::init_with_level(log::Level::Debug); console_error_panic_hook::set_once(); - - // logging::log!("csr mode - mounting to body"); - - mount_to_body(|| { - view! { } - }); + leptos::mount::mount_to_body(|| { + view! { + + + + } + }) } From cc497afc06197665ceb2e99bf60d97b66ecf0f13 Mon Sep 17 00:00:00 2001 From: oyelowo Date: Fri, 17 Jan 2025 20:28:46 +0200 Subject: [PATCH 08/11] Update version and metadata --- Cargo.toml | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6812d67..8fc1453 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,12 +5,25 @@ members = ["twust-macro", "tailwind"] [workspace.package] name = "twust" -version = "1.0.4" +version = "1.0.5" edition = "2021" authors = ["Oyelowo Oyedayo"] -description = "One codebase to rule them all" -documentation = "https://codebreather.com/oyelowo" +email = ["oyelowo.oss@gmai.com"] +description = "Zero-config Static type-checker for Tailwind CSS" +# documentation = "https://codebreather.com/oyelowo" license = "MIT/Apache-2.0" +categories = ["UI", "css", "tailwindcss", "web-programming"] +keywords = [ + "tailwind", + "css", + "tailwindcss", + "frontend", + "ui", + "rust", + "web", + "twust", +] + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html From 4b76fe09b7ca936c955602190df97b4d1627a906 Mon Sep 17 00:00:00 2001 From: oyelowo Date: Fri, 17 Jan 2025 20:49:14 +0200 Subject: [PATCH 09/11] Update metadata --- Cargo.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8fc1453..85077fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,8 +9,10 @@ version = "1.0.5" edition = "2021" authors = ["Oyelowo Oyedayo"] email = ["oyelowo.oss@gmai.com"] -description = "Zero-config Static type-checker for Tailwind CSS" +readme = "README.md" +documentation = "https://docs.rs/nom" # documentation = "https://codebreather.com/oyelowo" +description = "Zero-config Static type-checker for Tailwind CSS" license = "MIT/Apache-2.0" categories = ["UI", "css", "tailwindcss", "web-programming"] keywords = [ From 298b24184a701821d8737d793029eb620aefbfec Mon Sep 17 00:00:00 2001 From: oyelowo Date: Fri, 17 Jan 2025 20:49:21 +0200 Subject: [PATCH 10/11] Refactor macros --- twust-macro/src/config/macros.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/twust-macro/src/config/macros.rs b/twust-macro/src/config/macros.rs index 52e06bf..4b59675 100644 --- a/twust-macro/src/config/macros.rs +++ b/twust-macro/src/config/macros.rs @@ -54,7 +54,7 @@ macro_rules! define_tailwind_color_field { fn get_default(&self, config: &TailwindConfig) -> Vec<&str> { if let Some(ref core_plugins) = config.core_plugins { if let Some(enabled) = core_plugins.$default_field { - if enabled == false { + if !enabled { return vec![]; } } @@ -65,7 +65,7 @@ macro_rules! define_tailwind_color_field { fn get_override(&self, config: &TailwindConfig) -> Vec { if let Some(ref core_plugins) = config.core_plugins { if let Some(enabled) = core_plugins.$default_field { - if enabled == false { + if !enabled { return vec![]; } } @@ -80,7 +80,7 @@ macro_rules! define_tailwind_color_field { fn get_extend(&self, config: &TailwindConfig) -> Vec { if let Some(ref core_plugins) = config.core_plugins { if let Some(enabled) = core_plugins.$default_field { - if enabled == false { + if !enabled { return vec![]; } } @@ -117,7 +117,7 @@ macro_rules! define_tailwind_field { fn get_default(&self, config: &TailwindConfig) -> Vec<&str> { if let Some(ref core_plugins) = config.core_plugins { if let Some(enabled) = core_plugins.$field_name { - if enabled == false { + if !enabled { return vec![]; } } @@ -129,7 +129,7 @@ macro_rules! define_tailwind_field { fn get_override(&self, config: &TailwindConfig) -> Vec { if let Some(ref core_plugins) = config.core_plugins { if let Some(enabled) = core_plugins.$field_name { - if enabled == false { + if !enabled { return vec![]; } } @@ -144,7 +144,7 @@ macro_rules! define_tailwind_field { fn get_extend(&self, config: &TailwindConfig) -> Vec { if let Some(ref core_plugins) = config.core_plugins { if let Some(enabled) = core_plugins.$field_name { - if enabled == false { + if !enabled { return vec![]; } } From 233fab771a423676f896a27b42783c7f1d0a7cad Mon Sep 17 00:00:00 2001 From: oyelowo Date: Fri, 17 Jan 2025 20:53:11 +0200 Subject: [PATCH 11/11] Support placeholder color and opacity --- twust-macro/src/config/classes.rs | 18 ++++++++++++++++++ twust-macro/src/config/mod.rs | 4 +++- twust-macro/src/tailwind/default_classnames.rs | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/twust-macro/src/config/classes.rs b/twust-macro/src/config/classes.rs index 01effdf..1556eca 100644 --- a/twust-macro/src/config/classes.rs +++ b/twust-macro/src/config/classes.rs @@ -516,6 +516,24 @@ define_tailwind_field!({ variants: [] }); +// 3. Placeholder +// Placeholder Color +// Placeholder Opacity +define_tailwind_color_field!({ + name: PlaceholderColor, + prefix: "placeholder-color", + field_name: placeholder_color, + variants: [] +}); + +define_tailwind_field!({ + name: PlaceholderOpacity, + prefix: "placeholder-opacity", + inherited: placeholder_opacity, + field_name: placeholder_opacity, + variants: [] +}); + // 3. Spacing // Padding // Margin diff --git a/twust-macro/src/config/mod.rs b/twust-macro/src/config/mod.rs index 54a4f91..5b3c9a4 100644 --- a/twust-macro/src/config/mod.rs +++ b/twust-macro/src/config/mod.rs @@ -86,7 +86,7 @@ pub fn get_classes(config: &TailwindConfig) -> Vec { // by the user. let mut classes = Vec::new(); - let utilities: [Box; 175] = [ + let utilities: [Box; 177] = [ Box::new(AspectRatio), Box::new(Container), Box::new(Columns), @@ -143,6 +143,8 @@ pub fn get_classes(config: &TailwindConfig) -> Vec { Box::new(PlaceContent), Box::new(PlaceItems), Box::new(PlaceSelf), + Box::new(PlaceholderColor), + Box::new(PlaceholderOpacity), Box::new(Padding), Box::new(Margin), Box::new(SpaceBetween), diff --git a/twust-macro/src/tailwind/default_classnames.rs b/twust-macro/src/tailwind/default_classnames.rs index 193e5ae..52fdafb 100644 --- a/twust-macro/src/tailwind/default_classnames.rs +++ b/twust-macro/src/tailwind/default_classnames.rs @@ -7,6 +7,7 @@ // placescreen_readers-shown // placeholder-slate-400 +#[allow(dead_code)] #[derive(Debug, Clone, Copy)] pub struct TailWindCssDefaultClassNames { pub aspect_ratio: [&'static str; 3],