From eacaf3b163b8e90ffa6efee07efed6f608d10659 Mon Sep 17 00:00:00 2001 From: yiffyrusdev Date: Thu, 8 May 2025 19:52:13 +0500 Subject: [PATCH] fix: update doctests --- .github/workflows/cbt.yml | 3 +-- README.md | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cbt.yml b/.github/workflows/cbt.yml index 23416dd..ad3f3f1 100644 --- a/.github/workflows/cbt.yml +++ b/.github/workflows/cbt.yml @@ -17,13 +17,12 @@ jobs: matrix: toolchain: - stable - - nightly steps: - uses: actions/checkout@v4 - run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }} - run: cargo build --verbose - run: cargo test --verbose --all - - run: cargo test --verbose --all --all-features + - run: cargo test --verbose --all --features "const-scoping lepty-scoping" build_examples: name: Sabry - latset - examples diff --git a/README.md b/README.md index 857ad5e..29b42b7 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,10 @@ Compile all the sweet SASS/SCSS into the optimized CSS bundle, ship it in CSS sh ```rust sabry::styly!(cssbundle {".c1 {color: white;}"}); +``` + +```rust,ignore +// requires `const-scoping` feature sabry::styly!(const binary {".c2 {color: black;}"}); ``` @@ -158,7 +162,7 @@ And create a style scope wherever you want: // breadbadgelist.rs use sabry::styly; -styly!(const styles {" +styly!(styles {" .badges { display: flex; &__list { @@ -173,9 +177,7 @@ styly!(const styles {" /* Now you can use all scoped selectors: */ let badges_scoped_class = styles::badges; let wolf_scoped_id = styles::thewolf; -let badges__list_scoped_class = styles::___list(styles::badges); ``` -> That `const` usage is covered in the [following](#constant-styly-scopes) section. In this example we dont invoke sabry build-magic, so, to be as close to real life as possible, I used a const. Every selector, if that does make sense, now available for you as a member of `styles` scope. In this example - `styles::badges`, `styles::thewolf` and `styles::_list()`. More about scoping and member names you can read [here](#styly-scopes). @@ -267,6 +269,7 @@ pub const fn css() -> &'static str { // utils.rs use sabry::styly; +// required `const-scoping` feature styly!(pub const scope:scss {" .whatever { &__code {} @@ -274,6 +277,7 @@ styly!(pub const scope:scss {" } "}); +// requires `const-scoping` feature styly!(pub const another:scss {" .whatever { &__code {} @@ -290,6 +294,7 @@ pub const fn css() -> &'static str { // form.rs use sabry::styly; +// requires `const-scoping` feature styly!(pub const scope:scss {" .whatever { &__code {} @@ -297,6 +302,7 @@ styly!(pub const scope:scss {" } "}); +// requires `const-scoping` feature styly!(pub const another:scss {" .whatever { &__code {} @@ -539,6 +545,9 @@ use sabry::styly; styly!(private_fox {".fur {color: red; &-dark {color: black;}}"}); styly!(pub public_fox {".fur {color: red; &-dark {color: black;}}"}); +``` +```rust,ignore +// requires `const-scoping` feature styly!(pub const pub_compiletime_fox:sass {" .fur color: red @@ -546,6 +555,7 @@ styly!(pub const pub_compiletime_fox:sass {" color: black "}); ``` + Every of those calls will produce the styling scope as a module. Differences are explained right below. In general the scope does look like this: @@ -582,7 +592,7 @@ As you've seen above, scope doe not contain any style code by itself. That's the However you could still compile styles into the artifact by simply adding the `const` to the macro call: -```rust +```rust,ignore // Requires `const-scoping` feature sabry::styly!(const scope "tests/assets/mixin-module.scss"); ``` @@ -720,12 +730,15 @@ Not any valid CSS selector is a valid rust identifier. In general this section s **lepty-scoping** - overhauls the scope generation logic, best suitable for the leptos. Check out the [section](#leptos-specials) and an [example](https://github.com/yiffyrusdev/sabry/tree/master/examples/leptos-axum) +**const-scoping** - unlocks `styly!(const scope...` compile-time SASS->CSS generation, which seems to break WASM builds without special treatment (https://docs.rs/getrandom/latest/getrandom/#webassembly-support). Idk why, but it started to happen just recently + **nightly** - allows relative path selection with `scssy!` and `styly!` macros. However rust-analyzer will raise false-positives for reachable files as well. ## WIP *(sorted by my own priority)*, "dones" are excluded +- [ ] Why does `const scope` break WASM build? Everything was fine untill recent. This feature isn't top-priority, I dont personally use it, but still curious - [x] Somehow achieve the autocompletion for scopes. The problem is explained in details [here](https://github.com/yiffyrusdev/sabry/issues/2) - [x] some weird unrelated stuff I can see in autocompletion (still investigating btw) - [ ] Support for direct CSS syntax