From 8f1968d5063d5691a9d2c278e106cd381dd15cf4 Mon Sep 17 00:00:00 2001
From: Nico Burniske <46934294+nicoburniske@users.noreply.github.com>
Date: Fri, 12 Apr 2024 13:12:25 -0400
Subject: [PATCH] Global Override OnceLock (#21)
* attempt global override with compile time env value
* set_tw_options OnceLock
* Remove unused .cargo/config.toml
* fix doc test
* fix clippy error, use copied
* improved docs
* update readme
* small readme update
* remove prefix from example
* example fixes
* fix broken doc link
* remove inline annotation
---
README.md | 29 ++++++++
example/start-axum/Cargo.lock | 68 ++++++------------
example/start-axum/Cargo.toml | 4 +-
example/start-axum/src/app.rs | 2 +-
example/start-axum/src/button.rs | 22 +++---
example/start-axum/src/lib.rs | 3 +-
fuse/src/core/join.rs | 2 +-
fuse/src/core/merge/config.rs | 50 +++++++++++++
fuse/src/core/merge/merge_impl.rs | 2 +-
fuse/src/core/merge/mod.rs | 114 ++++++++++++++----------------
fuse/src/core/mod.rs | 2 +-
fuse/src/lib.rs | 31 +++++++-
fuse/tests/override.rs | 8 +--
13 files changed, 205 insertions(+), 132 deletions(-)
create mode 100644 fuse/src/core/merge/config.rs
diff --git a/README.md b/README.md
index 698fe7d..a47b57f 100644
--- a/README.md
+++ b/README.md
@@ -69,6 +69,35 @@ assert_eq!(
)
```
+### Custom Tailwind Prefix/Separator
+
+Use [`merge::set_merge_options`] to set global options for [`tw_merge!`] and variant macros.
+
+This can only be set once. Subsequent calls will be ignored.
+
+```rust
+use tailwind_fuse::{*, merge::*};
+
+const OPTIONS: MergeOptions = MergeOptions {
+ prefix: "tw-",
+ separator: ":",
+};
+
+// Before setting options, the default (no prefix) is used
+assert_eq!(
+ "tw-bg-black tw-bg-white",
+ tw_merge!("tw-bg-black", "tw-bg-white"),
+);
+
+set_merge_options(OPTIONS);
+
+assert_eq!(
+ "tw-bg-white",
+ tw_merge!("tw-bg-black", "tw-bg-white"),
+);
+
+```
+
## Usage: Variants
diff --git a/example/start-axum/Cargo.lock b/example/start-axum/Cargo.lock
index 543db79..dd1ddf4 100644
--- a/example/start-axum/Cargo.lock
+++ b/example/start-axum/Cargo.lock
@@ -1979,11 +1979,20 @@ checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160"
[[package]]
name = "tailwind_fuse"
-version = "0.1.0"
+version = "0.2.0"
dependencies = [
- "tw_fuse",
- "tw_utils",
- "tw_variant_macro",
+ "nom",
+ "tailwind_fuse_macro",
+]
+
+[[package]]
+name = "tailwind_fuse_macro"
+version = "0.2.0"
+dependencies = [
+ "darling 0.20.8",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.52",
]
[[package]]
@@ -2190,37 +2199,6 @@ dependencies = [
"once_cell",
]
-[[package]]
-name = "tw_ast"
-version = "0.1.0"
-dependencies = [
- "nom",
-]
-
-[[package]]
-name = "tw_fuse"
-version = "0.1.0"
-dependencies = [
- "nom",
- "tw_ast",
-]
-
-[[package]]
-name = "tw_utils"
-version = "0.1.0"
-
-[[package]]
-name = "tw_variant_macro"
-version = "0.1.0"
-dependencies = [
- "darling 0.20.8",
- "proc-macro2",
- "quote",
- "syn 2.0.52",
- "tw_fuse",
- "tw_utils",
-]
-
[[package]]
name = "typed-builder"
version = "0.18.1"
@@ -2333,9 +2311,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-bindgen"
-version = "0.2.89"
+version = "0.2.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e"
+checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
@@ -2343,9 +2321,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-backend"
-version = "0.2.89"
+version = "0.2.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826"
+checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da"
dependencies = [
"bumpalo",
"log",
@@ -2370,9 +2348,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
-version = "0.2.89"
+version = "0.2.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2"
+checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@@ -2380,9 +2358,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
-version = "0.2.89"
+version = "0.2.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283"
+checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7"
dependencies = [
"proc-macro2",
"quote",
@@ -2393,9 +2371,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-shared"
-version = "0.2.89"
+version = "0.2.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f"
+checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96"
[[package]]
name = "wasm-streams"
diff --git a/example/start-axum/Cargo.toml b/example/start-axum/Cargo.toml
index ef61136..588b5df 100644
--- a/example/start-axum/Cargo.toml
+++ b/example/start-axum/Cargo.toml
@@ -16,11 +16,11 @@ leptos_router = { version = "0.6", features = ["nightly"] }
tokio = { version = "1", features = ["rt-multi-thread"], optional = true }
tower = { version = "0.4", optional = true }
tower-http = { version = "0.5", features = ["fs"], optional = true }
-wasm-bindgen = "=0.2.89"
+wasm-bindgen = "=0.2.92"
thiserror = "1"
tracing = { version = "0.1", optional = true }
http = "1"
-tailwind_fuse = { path = "../../public", features = ["variant"]}
+tailwind_fuse = { path = "../../fuse", features = ["variant", "debug"]}
[features]
hydrate = ["leptos/hydrate", "leptos_meta/hydrate", "leptos_router/hydrate"]
diff --git a/example/start-axum/src/app.rs b/example/start-axum/src/app.rs
index 4ea583f..b415cb9 100644
--- a/example/start-axum/src/app.rs
+++ b/example/start-axum/src/app.rs
@@ -40,7 +40,7 @@ fn HomePage() -> impl IntoView {
let on_click = move |_| set_count.update(|count| *count += 1);
view! {
-
+