### Setup Fuzz Test Environment Source: https://github.com/avencera/rustywind/blob/master/xtask/README.md Builds the RustyWind release binary and installs npm dependencies in the fuzz test directory. This command is often run automatically by `fuzz run`. ```bash cargo xtask fuzz setup ``` -------------------------------- ### Rustywind Arguments: Path Examples Source: https://github.com/avencera/rustywind/blob/master/_autodocs/10-cli-reference.md Demonstrates various ways to specify file or directory paths for processing. ```bash rustywind . ``` ```bash rustywind src/ ``` ```bash rustywind src/**/*.tsx ``` ```bash rustywind src/index.tsx src/App.css ``` ```bash rustywind *.html ``` -------------------------------- ### Rustywind Binary Name Source: https://github.com/avencera/rustywind/blob/master/_autodocs/10-cli-reference.md Shows the available installation methods for the rustywind binary. ```bash rustywind ``` ```bash npx rustywind ``` ```bash cargo install rustywind ``` ```bash brew install avencera/tap/rustywind ``` ```bash docker run --rm -v $PWD:/app avencera/rustywind:latest ``` -------------------------------- ### Install RustyWind via GitHub Release Script Source: https://github.com/avencera/rustywind/blob/master/README.md Install RustyWind by downloading and executing an installation script from GitHub releases. ```bash curl -LSfs https://avencera.github.io/rustywind/install.sh | sh -s -- --git avencera/rustywind ``` -------------------------------- ### VariantInfo Examples Source: https://github.com/avencera/rustywind/blob/master/_autodocs/07-types-reference.md Illustrates how to create simple and compound VariantInfo instances. ```rust VariantInfo::simple("hover") ``` ```rust VariantInfo::compound("group", VariantInfo::simple("hover")) ``` -------------------------------- ### Install RustyWind Source: https://github.com/avencera/rustywind/blob/master/npm/README.md Various methods to install the RustyWind CLI tool on your system. ```shell yarn global add rustywind ``` ```shell npm install -g rustywind ``` ```shell brew install avencera/taps/rustywind ``` ```shell curl -LSfs https://avencera.github.io/rustywind/install.sh | sh -s -- --git avencera/rustywind ``` ```shell docker run --rm -v $PWD:/app avencera/rustywind:latest ``` -------------------------------- ### Combined Options Examples Source: https://github.com/avencera/rustywind/blob/master/_autodocs/10-cli-reference.md Presents examples of using multiple Rustywind options together for advanced configurations, such as custom prefixes, class wrapping, and quiet operation for CI/CD. ```bash # Full featured: custom prefix, custom wrapping, preserve duplicates rustywind . \ --tailwind-prefix tw \ --class-wrapping comma-single-quotes \ --allow-duplicates \ --write ``` ```bash # CI/CD: check formatting with custom config rustywind . \ --check-formatted \ --config-file tailwind-order.json \ --quiet ``` -------------------------------- ### Install and Run Default npm Test Source: https://github.com/avencera/rustywind/blob/master/tests/fuzz/README.md Installs dependencies and runs the default npm test suite for fuzzing. Assumes a release RustyWind binary is available. ```bash cd tests/fuzz npm ci npm test ``` -------------------------------- ### Install RustyWind via Cargo Source: https://github.com/avencera/rustywind/blob/master/README.md Install RustyWind using the Cargo package manager. ```bash cargo install rustywind ``` ```bash cargo binstall rustywind ``` -------------------------------- ### Install RustyWind via npm Source: https://github.com/avencera/rustywind/blob/master/README.md Install RustyWind globally using npm or yarn. ```bash npm install -g rustywind ``` ```bash yarn global add rustywind ``` -------------------------------- ### Install RustyWind via Homebrew Source: https://github.com/avencera/rustywind/blob/master/README.md Install RustyWind on macOS and Linux using Homebrew. ```bash brew install avencera/tap/rustywind ``` -------------------------------- ### Rust Example: Getting CSS Properties Source: https://github.com/avencera/rustywind/blob/master/_autodocs/05-class-parser.md Shows how to use the `get_properties()` method on a parsed class to retrieve the generated CSS property names. ```rust let parsed = parse_class("mx-4").unwrap(); if let Some(props) = parsed.get_properties() { for prop in props { println!("Generates CSS property: {}", prop); } } ``` -------------------------------- ### Pattern-Based Sorting: Arbitrary Values Examples Source: https://github.com/avencera/rustywind/blob/master/_autodocs/09-sorting-algorithm.md Demonstrates how arbitrary values in class names are parsed and sorted alphabetically after standard values. ```text w-[500px] → utility: "w", value: "[500px]" max-w-[min(100%, 500px)] → utility: "max-w", value: "[min(100%, 500px)]" ``` ```text p-4, p-[1.5rem] → p-4 before p-[1.5rem] w-full, w-[500px] → w-full before w-[500px] ``` -------------------------------- ### JSON Configuration File Format Source: https://github.com/avencera/rustywind/blob/master/_autodocs/08-configuration.md Example of a JSON configuration file used to define a custom class sorting order. ```json { "sortOrder": [ "flex", "grid", "container", "block", "hidden", "p-0", "p-1", "p-2", "p-4", "m-0", "m-1", "m-2", "m-4" ] } ``` -------------------------------- ### Pattern-Based Sorting: Numeric Value Examples Source: https://github.com/avencera/rustywind/blob/master/_autodocs/09-sorting-algorithm.md Shows how classes with the same utility but different numeric values are sorted numerically. ```text p-2, p-4, p-8 → sorted: p-2, p-4, p-8 (2 < 4 < 8) m-1, m-6, m-2 → sorted: m-1, m-2, m-6 ``` ```text w-1/2, w-1/3, w-1/4 → sorted by numeric value: 1/4 < 1/3 < 1/2 ``` -------------------------------- ### File Selection Examples Source: https://github.com/avencera/rustywind/blob/master/_autodocs/10-cli-reference.md Illustrates various ways to specify files and directories for Rustywind to process, including single files, multiple directories, glob patterns, and exclusion lists. ```bash # Specific file rustywind src/index.tsx ``` ```bash # Directory rustywind src/ ``` ```bash # Multiple directories rustywind src/ components/ ``` ```bash # With glob pattern rustywind "**/*.{html,tsx,jsx}" ``` ```bash # Exclude node_modules rustywind . --ignored-files node_modules ``` -------------------------------- ### Pattern-Based Sorting: Property Count Example Source: https://github.com/avencera/rustywind/blob/master/_autodocs/09-sorting-algorithm.md Compares multi-property utilities against single-property utilities, with multi-property utilities sorting first. ```text inset-0 ← affects: top, right, bottom, left (4 properties) top-0 ← affects: top (1 property) inset-0 comes first ``` -------------------------------- ### Rust Example: Parsing with Responsive Variant Source: https://github.com/avencera/rustywind/blob/master/_autodocs/05-class-parser.md Shows how to parse a class name that includes a responsive variant, such as 'md:mx-4'. ```rust let parsed = parse_class("md:mx-4").unwrap(); assert_eq!(parsed.variants, vec!["md"]); assert_eq!(parsed.utility, "mx"); assert_eq!(parsed.value, "4"); ``` -------------------------------- ### Class Wrapping Examples Source: https://github.com/avencera/rustywind/blob/master/_autodocs/10-cli-reference.md Demonstrates how to apply different class wrapping formats using the `--class-wrapping` option, specifically for comma-quoted and double-quoted array styles. ```bash # Convert to comma-quoted format rustywind . --class-wrapping comma-single-quotes --write ``` ```bash # Convert to double-quoted array format rustywind . --class-wrapping comma-double-quotes --write ``` -------------------------------- ### Piping and Redirection Examples Source: https://github.com/avencera/rustywind/blob/master/_autodocs/10-cli-reference.md Shows how to integrate Rustywind with shell pipes and redirection for tasks like sorting file content, viewing diffs, and saving output to different files. ```bash # Sort HTML template and save to new file cat template.html | rustywind --stdin > sorted.html ``` ```bash # View diff before applying rustywind . --dry-run | diff -u original.html - || true ``` ```bash # Sort and write to different location rustywind src/index.tsx --dry-run > sorted_output.tsx ``` ```bash # Suppress output when using --write rustywind . --write --quiet ``` -------------------------------- ### Basic Sorting Examples Source: https://github.com/avencera/rustywind/blob/master/_autodocs/10-cli-reference.md Demonstrates fundamental Rustywind operations: dry run to preview changes, writing changes directly to files, and checking if files are already formatted. ```bash # Dry run on current directory rustywind . ``` ```bash # View changes before applying rustywind . --dry-run ``` ```bash # Apply changes to all files rustywind . --write ``` ```bash # Check if files are formatted rustywind . --check-formatted && echo "All formatted!" || echo "Need formatting" ``` -------------------------------- ### RustyWind CLI for Piping and Automation Source: https://github.com/avencera/rustywind/blob/master/_autodocs/11-code-examples.md Shows examples of using RustyWind with standard input/output, saving sorted output to a file, integrating into CI/CD pipelines, and suppressing output. ```bash # Sort HTML from stdin echo '
' | rustywind --stdin # Save sorted output to file rustywind src/index.tsx --dry-run > sorted.tsx # Use in CI/CD pipeline rustywind . --check-formatted && echo "OK" || echo "Fix formatting" # Sort and suppress output rustywind . --write --quiet # View diff before applying diff -u <(rustywind . --dry-run) original.html ``` -------------------------------- ### Pattern-Based Sorting: Utility Prefix Priority Example Source: https://github.com/avencera/rustywind/blob/master/_autodocs/09-sorting-algorithm.md Illustrates sorting by utility base name when property and values match, using alphabetical order as a tiebreaker. ```text gap-4, space-4 ← both affect spacing but different utilities gap-4 < space-4 (alphabetically) ``` -------------------------------- ### Example: Skip SSL Verification with Vite CSS and Write Source: https://github.com/avencera/rustywind/blob/master/_autodocs/10-cli-reference.md Demonstrates running RustyWind with `--vite-css` and `--skip-ssl-verification` for a development server using self-signed certificates, combined with the `--write` flag to apply formatting. ```bash # Dev server with self-signed cert rustywind . --vite-css "https://localhost:5173/css" \ --skip-ssl-verification \ --write ``` -------------------------------- ### Pattern-Based Sorting: Unknown Classes Example Source: https://github.com/avencera/rustywind/blob/master/_autodocs/09-sorting-algorithm.md Illustrates how unrecognized classes are placed at the end of the sorted output, maintaining their original relative order. ```text flex, my-custom, p-4 Sorted: flex, p-4, my-custom ← my-custom at end ``` -------------------------------- ### Tailwind Prefix Examples Source: https://github.com/avencera/rustywind/blob/master/_autodocs/10-cli-reference.md Illustrates the use of the `--tailwind-prefix` option to handle Tailwind classes with custom prefixes like 'tw:' or 'tw-'. ```bash # Handle tw: prefix rustywind . --tailwind-prefix tw --write ``` ```bash # Handle tw- prefix rustywind . --tailwind-prefix tw --write ``` -------------------------------- ### Custom Regex Example Usage Source: https://github.com/avencera/rustywind/blob/master/_autodocs/08-configuration.md Command to run RustyWind with a custom regex pattern for class extraction. ```bash rustywind . --custom-regex '(["\'])(?:(?=(\\.)*\\1.)*?(\\.1[^\1\\]*?)*?([^\1\\]*?))\1' ``` -------------------------------- ### Pattern-Based Sorting: Variant Order Examples Source: https://github.com/avencera/rustywind/blob/master/_autodocs/09-sorting-algorithm.md Demonstrates how base classes are sorted before variant classes, and how different variants are ordered based on their index in the VARIANT_ORDER array. ```text flex ← base class hover:flex ← has variant md:flex ← has variant md:hover:flex ← has variants ``` ```text hover:flex ← hover at index 46 focus:flex ← focus at index 47 md:flex ← md (responsive) at index 72 dark:flex ← dark at index 80 ``` -------------------------------- ### Print Version Number Source: https://github.com/avencera/rustywind/blob/master/_autodocs/10-cli-reference.md Outputs the currently installed version of Rustywind. Use either the short (-V) or long (--version) flag. ```bash rustywind --version ``` ```bash rustywind -V ``` -------------------------------- ### Pattern-Based Sorting: Property Index Examples Source: https://github.com/avencera/rustywind/blob/master/_autodocs/09-sorting-algorithm.md Illustrates sorting based on the index of the CSS property generated by a utility class, using the PROPERTY_ORDER array. ```text 0: background-opacity 1: container-type 2: pointer-events 3: visibility 4: position ... 25: margin 26: display ... 252: padding ``` ```text m-4 ← margin (index ~25) flex ← display (index ~26) p-4 ← padding (index ~252) Sorted: m-4, flex, p-4 ``` -------------------------------- ### Custom CSS-Based Sorter Example Source: https://github.com/avencera/rustywind/blob/master/_autodocs/09-sorting-algorithm.md Illustrates the process of creating a custom sorter using a CSS file. It shows the CSS input, the resulting HashMap, the input class string, and the final sorted output. ```text CSS file: .container { } .p-4 { } .flex { } .m-4 { } Mapping: {container: 0, p-4: 1, flex: 2, m-4: 3} Input: flex m-4 p-4 container unknown Sorted: container p-4 flex m-4 unknown (by index, unknown at end) ``` -------------------------------- ### Rust Example: Simple Utility Parsing Source: https://github.com/avencera/rustywind/blob/master/_autodocs/05-class-parser.md Demonstrates parsing a basic Tailwind CSS utility class like 'flex' to extract its utility name, value, and variants. ```rust use rustywind_core::class_parser::parse_class; // Simple utility let parsed = parse_class("flex").unwrap(); assert_eq!(parsed.utility, "flex"); assert_eq!(parsed.value, ""); assert_eq!(parsed.variants.len(), 0); assert!(!parsed.important); ``` -------------------------------- ### Pattern-Based Sorting: Compound Variants Examples Source: https://github.com/avencera/rustywind/blob/master/_autodocs/09-sorting-algorithm.md Shows how compound variants like 'group-hover' are parsed and ordered based on their base and modifier components. ```text group:flex ← group variant, no modifier group-hover:flex ← group variant with hover modifier group-focus:flex ← group variant with focus modifier peer:flex ← peer variant, no modifier peer-hover:flex ← peer variant with hover modifier ``` -------------------------------- ### Variant Sorting Example Source: https://github.com/avencera/rustywind/blob/master/_autodocs/09-sorting-algorithm.md Demonstrates the sorting of classes based on variant order. Classes with variants that appear earlier in `VARIANT_ORDER` are sorted first. ```text print:flex ← print at index 81 dark:flex ← dark at index 80 focus:flex ← focus at index 47 hover:flex ← hover at index 46 Sorted (by variant index): hover:flex, focus:flex, dark:flex, print:flex ``` -------------------------------- ### NoWrapping Mode Example Source: https://github.com/avencera/rustywind/blob/master/_autodocs/06-class-wrapping.md Demonstrates sorting classes for HTML/JSX attributes using `NoWrapping` mode. Input classes are space-separated and output maintains space separation. ```rust use rustywind_core::RustyWind; use rustywind_core::class_wrapping::ClassWrapping; let app = RustyWind { class_wrapping: ClassWrapping::NoWrapping, ..Default::default() }; let html = r###"
"###; let sorted = app.sort_file_contents(html); // Output:
``` -------------------------------- ### Custom Sorting Examples Source: https://github.com/avencera/rustywind/blob/master/_autodocs/10-cli-reference.md Shows how to customize Rustywind's sorting behavior using external CSS files, JSON configuration files, or custom regular expressions for array formats. ```bash # Use custom sort order from CSS rustywind . --output-css-file dist/tailwind.css --write ``` ```bash # Use custom sort order from JSON rustywind . --config-file sort-order.json --write ``` ```bash # Custom regex for array format rustywind . --custom-regex '(?:\['_a-zA-Z0-9\.,\-\'"\s]+)(?:\])' --write ``` -------------------------------- ### Rust Example: Checking for Variants Source: https://github.com/avencera/rustywind/blob/master/_autodocs/05-class-parser.md Demonstrates how to check if a parsed class has any variants and retrieve the count of variants using `has_variants()` and `variant_count()` methods. ```rust let parsed = parse_class("md:p-4").unwrap(); if parsed.has_variants() { println!("Has {} variants", parsed.variant_count()); } ``` -------------------------------- ### Exit Codes Examples Source: https://github.com/avencera/rustywind/blob/master/_autodocs/10-cli-reference.md Demonstrates how to interpret Rustywind's exit codes to determine the success or failure of an operation, including success, files needing formatting, and errors. ```bash # Success rustywind . --write echo $? # Output: 0 ``` ```bash # Files need formatting rustywind . --check-formatted && all_good=true || all_good=false echo $all_good # Output: false ``` ```bash # Error (file not found) rustywind /nonexistent/path echo $? # Output: 2 ``` -------------------------------- ### Run Fuzz Tests (Default) Source: https://github.com/avencera/rustywind/blob/master/xtask/README.md Executes fuzz tests with the default number of rounds and auto-detected worker count. Setup is automatically performed if needed. ```bash cargo xtask fuzz run ``` -------------------------------- ### Complex Class String Parsing and Sorting Source: https://github.com/avencera/rustywind/blob/master/_autodocs/09-sorting-algorithm.md An example demonstrating the parsing of a complex class string, including utilities, variants, and unknown classes, followed by the sorting logic. ```text Input: "p-4 m-4 flex hover:flex md:p-4 my-custom" Parsing: p-4 → utility: p, value: 4, variants: [] m-4 → utility: m, value: 4, variants: [] flex → utility: flex, value: "", variants: [] hover:flex → utility: flex, value: "", variants: [hover] md:p-4 → utility: p, value: 4, variants: [md] my-custom → unknown class Sorting (by property, then variant, then numeric): Base classes first (no variants): - m-4 (margin, index ~25) - flex (display, index ~26) - p-4 (padding, index ~252) Then variant classes (by variant order): - hover:flex (hover index 46) - md:p-4 (md index 72) Unknown classes at end: - my-custom Output: "m-4 flex p-4 hover:flex md:p-4 my-custom" ``` -------------------------------- ### Rust Example: Parsing Multiple Variants Source: https://github.com/avencera/rustywind/blob/master/_autodocs/05-class-parser.md Illustrates parsing a class name with multiple variants, demonstrating that they are stored in right-to-left order, e.g., 'hover:focus:bg-red-500'. ```rust let parsed = parse_class("hover:focus:bg-red-500").unwrap(); assert_eq!(parsed.variants, vec!["focus", "hover"]); assert_eq!(parsed.utility, "bg"); assert_eq!(parsed.value, "red-500"); ``` -------------------------------- ### Rust Example: Rebuilding Class String Source: https://github.com/avencera/rustywind/blob/master/_autodocs/05-class-parser.md Demonstrates how to reconstruct the original Tailwind CSS class string from its parsed components (variants, utility, value, important modifier). ```rust let parsed = parse_class("md:p-4").unwrap(); let rebuilt = format!( " ``` ```text ``` ```text ``` ```text ``` ```text ``` ```text ``` ```text ``` ```text ``` -------------------------------- ### Example: CI/CD Linting Source: https://github.com/avencera/rustywind/blob/master/_autodocs/08-configuration.md Integrates RustyWind into CI/CD pipelines for linting. The `--check-formatted` flag ensures files are correctly sorted, and the exit code indicates the formatting status. ```bash rustywind . --check-formatted echo $? ``` -------------------------------- ### RustyWind CLI with Custom Configuration Source: https://github.com/avencera/rustywind/blob/master/_autodocs/11-code-examples.md Demonstrates how to use RustyWind with custom configurations, such as specifying an output CSS file, using a custom JSON configuration file, or defining a custom regex pattern. ```bash # Custom CSS file for sort order rustywind . --output-css-file dist/tailwind.css --write # Custom JSON config rustywind . --config-file tailwind-order.json --write # Custom regex pattern rustywind . --custom-regex '(?:\['))([\"_a-zA-Z0-9.,\-\s]+)(?:\'])' --write ``` -------------------------------- ### RustyWind CLI Help Output Source: https://github.com/avencera/rustywind/blob/master/npm/README.md Full command-line interface help documentation detailing all available options and arguments. ```shell Usage: rustywind [OPTIONS] [PATH]... Run rustywind with a path to get a list of files that will be changed rustywind . --dry-run If you want to reorganize all classes in place, and change the files run with the `--write` flag rustywind --write . To print only the file names that would be changed run with the `--check-formatted` flag rustywind --check-formatted . If you want to run it on your STDIN, you can do: echo "" | rustywind --stdin Arguments: [PATH]... A file or directory to run on Options: --stdin Uses stdin instead of a file or folder --write Changes the files in place with the reorganized classes --dry-run Prints out the new file content with the sorted classes to the terminal --check-formatted Checks if the files are already formatted, exits with 1 if not formatted --allow-duplicates When set, RustyWind will not delete duplicated classes --config-file When set, RustyWind will use the config file to derive configurations. The config file current only supports json with one property sortOrder, e.g. { "sortOrder": ["class1", ...] } --output-css-file When set RustyWind will determine the sort order by the order the class appear in the the given css file --vite-css When set RustyWind will determine the sort order by the order the class appear in the CSS file that vite generates. Please provide the full URL to the CSS file ex: `rustywind --vite-css "http://127.0.0.1:5173/src/assets/main.css" . --dry-run` Note: This option is experimental and may be removed in the future. --skip-ssl-verification When set, RustyWind will skip SSL verification for the vite_css option --ignored-files When set, RustyWind will ignore this list of files --custom-regex Uses a custom regex instead of default one -h, --help Print help (see a summary with '-h') -V, --version Print version ``` -------------------------------- ### Rust Example: Re-parsing Important Modifier Source: https://github.com/avencera/rustywind/blob/master/_autodocs/05-class-parser.md This example re-demonstrates parsing a class with an important modifier, ensuring it's correctly identified. ```rust let parsed = parse_class("p-4!").unwrap(); assert!(parsed.important); ``` -------------------------------- ### Rust Example: Parsing with Important Modifier Source: https://github.com/avencera/rustywind/blob/master/_autodocs/05-class-parser.md Demonstrates parsing a class name that includes the important modifier '!', such as 'p-4!'. ```rust let parsed = parse_class("p-4!").unwrap(); assert!(parsed.important); assert_eq!(parsed.utility, "p"); assert_eq!(parsed.value, "4"); ``` -------------------------------- ### Performance Tip: Reuse RustyWind Instance Source: https://github.com/avencera/rustywind/blob/master/_autodocs/11-code-examples.md Demonstrates the efficient approach of creating a single RustyWind instance and reusing it for multiple sorting operations, contrasting it with the inefficient method of creating a new instance for each file. ```rust // ✓ Good: Create once, use many times let app = RustyWind::default(); for file in files { let sorted = app.sort_file_contents(&content); } // ✗ Bad: Create new instance per file for file in files { let app = RustyWind::default(); let sorted = app.sort_file_contents(&content); } ``` -------------------------------- ### Custom Regex for Data Attribute Source: https://github.com/avencera/rustywind/blob/master/_autodocs/08-configuration.md Example of a custom regex pattern to extract class names from a 'data-classes' attribute. ```regex data-classes="([^"]+)" ``` -------------------------------- ### Rust: Get cache statistics Source: https://github.com/avencera/rustywind/blob/master/_autodocs/04-hybrid-sorter.md Retrieves and prints the current number of cache entries and the total capacity of the cache. ```rust let sorter = HybridSorter::new(); let _ = sorter.sort_classes(&["flex", "p-4", "m-4"]); let (entries, capacity) = sorter.cache_stats(); println!("Cache: {}/{}" entries, capacity); // Output: Cache: 3/7500 entries ``` -------------------------------- ### Performance Tip: Batch Processing in Parallel Source: https://github.com/avencera/rustywind/blob/master/_autodocs/11-code-examples.md Illustrates how to leverage `rayon` for parallel processing of files, enhancing performance for batch operations by sorting file contents concurrently using a shared `RustyWind` instance wrapped in `Arc`. ```rust use rayon::prelude::*; use rustywind_core::RustyWind; use std::sync::Arc; let app = Arc::new(RustyWind::default()); let sorted: Vec<_> = files .par_iter() .map(|file| { let content = std::fs::read_to_string(file).unwrap(); app.sort_file_contents(&content).to_string() }) .collect(); ``` -------------------------------- ### Print Help Message Source: https://github.com/avencera/rustywind/blob/master/_autodocs/10-cli-reference.md Displays the complete help message, listing all available command-line options and their descriptions. Can be invoked using either the short (-h) or long (--help) flag. ```bash rustywind --help ``` ```bash rustywind -h ``` -------------------------------- ### Rust Example: Parsing Arbitrary Value Source: https://github.com/avencera/rustywind/blob/master/_autodocs/05-class-parser.md Shows parsing a class name with an arbitrary value enclosed in brackets, like 'w-[500px]'. ```rust let parsed = parse_class("w-[500px]").unwrap(); assert_eq!(parsed.utility, "w"); assert_eq!(parsed.value, "[500px]"); ``` -------------------------------- ### Custom Regex for Tailwind Directive Source: https://github.com/avencera/rustywind/blob/master/_autodocs/08-configuration.md Example of a custom regex pattern to extract class names from Tailwind CSS's @apply directive. ```regex @apply\s+([^;]+); ``` -------------------------------- ### RustyWind CLI Usage Help Source: https://github.com/avencera/rustywind/blob/master/README.md Displays the help message for the RustyWind CLI, including available options and arguments. ```shell Usage: rustywind [OPTIONS] [PATH]... Run rustywind with a path to get a list of files that will be changed rustywind . --dry-run If you want to reorganize all classes in place, and change the files run with the `--write` flag rustywind --write . To print only the file names that would be changed run with the `--check-formatted` flag rustywind --check-formatted . If you want to run it on your STDIN, you can do: echo "" | rustywind --stdin Arguments: [PATH]... A file or directory to run on Options: --stdin Uses stdin instead of a file or folder --write Changes the files in place with the reorganized classes --dry-run Prints out the new file content with the sorted classes to the terminal --check-formatted Checks if the files are already formatted, exits with 1 if not formatted --allow-duplicates When set, RustyWind will not delete duplicated classes --config-file When set, RustyWind will use the config file to derive configurations. The config file current only supports json with one property sortOrder, e.g. { "sortOrder": ["class1", ...] } --output-css-file When set RustyWind will determine the sort order by the order the class appear in the the given css file --vite-css When set RustyWind will determine the sort order by the order the class appear in the CSS file that vite generates. Please provide the full URL to the CSS file ex: `rustywind --vite-css "http://127.0.0.1:5173/src/assets/main.css" . --dry-run` Note: This option is experimental and may be removed in the future. --skip-ssl-verification When set, RustyWind will skip SSL verification for the vite_css option --ignored-files When set, RustyWind will ignore this list of files --custom-regex Uses a custom regex instead of default one --quiet Do not print log messages -h, --help Print help (see a summary with '-h') -V, --version Print version ``` -------------------------------- ### Get CSS Properties from Parsed Class Source: https://github.com/avencera/rustywind/blob/master/_autodocs/11-code-examples.md Demonstrates how to retrieve the corresponding CSS properties for a parsed Tailwind class using the `get_properties` method. ```rust use rustywind_core::class_parser::parse_class; fn main() { let parsed = parse_class("mx-4").unwrap(); if let Some(props) = parsed.get_properties() { for prop in props { println!("CSS property: {}" prop); } } else { println!("Utility not recognized"); } } ``` -------------------------------- ### Configure Class Wrapping (Rust) Source: https://github.com/avencera/rustywind/blob/master/_autodocs/08-configuration.md Set the class wrapping mode programmatically in Rust using the `ClassWrapping` enum. This example demonstrates setting it to `CommaSingleQuotes`. ```rust let app = RustyWind { class_wrapping: ClassWrapping::CommaSingleQuotes, ..Default::default() }; ``` -------------------------------- ### Rust Example: Handling Invalid Empty String Source: https://github.com/avencera/rustywind/blob/master/_autodocs/05-class-parser.md Shows that parsing an empty string results in `None`, indicating an invalid or empty class name. ```rust assert!(parse_class("").is_none()); ``` -------------------------------- ### Rust Example: Arbitrary Variant with Colons Source: https://github.com/avencera/rustywind/blob/master/_autodocs/05-class-parser.md Demonstrates parsing a class name where the variant itself contains colons within brackets, like '[&>*:last-child]:rounded-b-lg'. ```rust let parsed = parse_class("[&>*:last-child]:rounded-b-lg").unwrap(); assert_eq!(parsed.variants, vec!["[&>*:last-child]"]); assert_eq!(parsed.utility, "rounded"); assert_eq!(parsed.value, "b-lg"); ``` -------------------------------- ### Rust: Basic class sorting Source: https://github.com/avencera/rustywind/blob/master/_autodocs/04-hybrid-sorter.md Demonstrates basic sorting of class names using HybridSorter, showing the output order based on Tailwind's property ordering. ```rust use rustywind_core::hybrid_sorter::HybridSorter; let sorter = HybridSorter::new(); let classes = vec!["p-4", "m-4", "flex"]; let sorted = sorter.sort_classes(&classes); println!("{:?}", sorted); // Output: ["m-4", "flex", "p-4"] (margin < display < padding) ``` -------------------------------- ### HashMap for Class Indices Source: https://github.com/avencera/rustywind/blob/master/_autodocs/09-sorting-algorithm.md Example of a HashMap mapping CSS class names to their assigned numerical indices for sorting. Used in both pattern-based and custom sorters. ```rust { "flex": 0, "p-4": 1, "m-4": 2, } ``` ```rust { "flex": 0, "p-4": 1, } ``` ```rust { "container": 0, "flex": 1, "p-4": 2, "m-4": 3, "hover:flex": 4, } ``` ```rust { "container": 0, "p-4": 1, "flex": 2, "m-4": 3, } ``` -------------------------------- ### Release Gate: Comprehensive Project Checks Source: https://github.com/avencera/rustywind/blob/master/tests/fuzz/docs/README.md A set of commands to ensure the project is ready for release, including running all tests, linting with Clippy, building in release mode, and executing npm tests within the fuzz directory. ```bash cargo test --workspace cargo clippy --workspace --all-targets -- -D warnings cargo build --release cd tests/fuzz && npm ci && npm test cd ../.. cargo xtask fuzz run 25 ``` -------------------------------- ### RustyWind::default Source: https://github.com/avencera/rustywind/blob/master/_autodocs/02-rustywind-type.md Creates a new RustyWind instance with all default values. This is useful for a quick setup with standard configurations for sorting Tailwind CSS classes. ```APIDOC ## RustyWind::default ### Description Creates a new instance with all default values: Pattern-based sorter, default regex for `class` and `className` attributes, duplicates removed, no class wrapping, and no Tailwind prefix. ### Method `Default::default()` ### Returns `RustyWind` — Configured instance ### Example ```rust let app = RustyWind::default(); let sorted = app.sort_file_contents(r"
"); ``` ``` -------------------------------- ### Run Fuzz Testing with xtask Source: https://github.com/avencera/rustywind/blob/master/tests/fuzz/README.md Builds the release binary and runs the fuzz testing suite using the Rust xtask wrapper for repeatable multi-round runs and failure analysis. ```bash cargo build --release cd tests/fuzz && npm ci cd ../.. cargo xtask fuzz run 25 ``` -------------------------------- ### Custom Regex for Array Format Classes Source: https://github.com/avencera/rustywind/blob/master/_autodocs/08-configuration.md Example of a custom regex pattern to extract class names from an array format (e.g., Python/JavaScript) enclosed in brackets. ```regex (?:\}{|\[)([_a-zA-Z0-9\.,\-'"]+)(?:\}|\]) ``` -------------------------------- ### Rustywind Option: Config File Source: https://github.com/avencera/rustywind/blob/master/_autodocs/10-cli-reference.md Loads custom class sort order from a JSON file. Mutually exclusive with --output-css-file and --vite-css. ```bash rustywind . --config-file tailwind-order.json ``` ```json { "sortOrder": ["flex", "grid", "p-4", "m-4"] } ``` ```bash rustywind . --config-file custom-sort.json --write ``` -------------------------------- ### Using a Custom Sorter from a File Source: https://github.com/avencera/rustywind/blob/master/_autodocs/03-sorter-module.md Shows how to create a sorter instance from a CSS file, enabling RustyWind to sort classes based on the order defined in that file. Requires opening a file and handling potential errors. ```rust use std::fs::File; use rustywind_core::RustyWind; use rustywind_core::sorter::{Sorter, FinderRegex}; let css_file = File::open("tailwind.css").unwrap(); let sorter = Sorter::new_from_file(css_file).unwrap(); let app = RustyWind { sorter, regex: FinderRegex::DefaultRegex, ..Default::default() }; let sorted = app.sort_classes("p-4 m-4 flex"); // Sorted according to order in tailwind.css ``` -------------------------------- ### RustyWind System Architecture Layers Source: https://github.com/avencera/rustywind/blob/master/_autodocs/12-architecture.md Illustrates the layered structure of RustyWind, from the CLI interface down to the parsing logic. ```text ┌─────────────────────────────────────────────┐ │ CLI Layer (rustywind-cli) │ │ ┌─────────────────────────────────────────┤ │ │ CLI Parsing │ File I/O │ Parallelization │ └─────────────────────────────────────────┘ │ ↓ ┌─────────────────────────────────────────────┐ │ Application Layer (rustywind-core) │ │ ┌─────────────────────────────────────────┤ │ │ RustyWind │ Regex Matching │ │ │ Class Wrapping │ Deduplication │ │ └─────────────────────────────────────────┘ │ ↓ ┌─────────────────────────────────────────────┐ │ Sorting Layer (rustywind-core) │ │ ┌─────────────────────────────────────────┤ │ │ HybridSorter (Cache + Pattern) │ │ │ PatternSorter │ CustomSorter │ │ └─────────────────────────────────────────┘ │ ↓ ┌─────────────────────────────────────────────┐ │ Parsing Layer (rustywind-core) │ │ ┌─────────────────────────────────────────┤ │ │ ClassParser │ VariantParser │ │ │ PropertyIndex │ VariantOrder │ │ └─────────────────────────────────────────┘ └─────────────────────────────────────────────┘ ``` -------------------------------- ### Tailwind Prefix Support Configuration Source: https://github.com/avencera/rustywind/blob/master/_autodocs/12-architecture.md Shows how to initialize RustyWind with support for Tailwind prefixes. ```rust let app = RustyWind::new_with_tailwind_prefix( FinderRegex::DefaultRegex, Sorter::PatternSorter, false, ClassWrapping::NoWrapping, Some("tw".to_string()), ); ``` -------------------------------- ### Performance Tip: Use Larger Cache for Batch Processing Source: https://github.com/avencera/rustywind/blob/master/_autodocs/11-code-examples.md Advises on using a larger cache size with `HybridSorter` for scenarios involving a high volume of files (10,000+) with numerous unique Tailwind classes to optimize performance. ```rust use rustywind_core::hybrid_sorter::HybridSorter; // For processing 10,000+ files with many unique classes let sorter = HybridSorter::with_cache_size(50_000); ``` -------------------------------- ### Custom Sorter Implementation Source: https://github.com/avencera/rustywind/blob/master/_autodocs/12-architecture.md Demonstrates how to provide a custom sorter implementation to RustyWind. ```rust let mut custom_order = HashMap::new(); // Populate with custom order let sorter = Sorter::new(custom_order); let app = RustyWind { sorter, ..Default::default() }; ``` -------------------------------- ### Set Custom Cache Size for RustyWind Source: https://github.com/avencera/rustywind/blob/master/_autodocs/11-code-examples.md Shows how to initialize RustyWind with a specific cache size, useful for projects with a large number of unique classes. ```rust use rustywind_core::hybrid_sorter::HybridSorter; fn main() { // For large projects with thousands of unique classes let sorter = HybridSorter::with_cache_size(50_000); let classes = vec!["flex", "grid", "p-4", "m-4"]; let sorted = sorter.sort_classes(&classes); println!("{:?}" sorted); } ``` -------------------------------- ### Rustywind Option: Output CSS File Source: https://github.com/avencera/rustywind/blob/master/_autodocs/10-cli-reference.md Determines sort order from a CSS file based on class appearance. Mutually exclusive with --config-file and --vite-css. ```bash rustywind . --output-css-file dist/styles.css ``` ```css .flex { } .p-4 { } .m-4 { } ``` ```bash npm run build # Generate tailwind.css rustywind . --output-css-file dist/tailwind.css --write ``` -------------------------------- ### Run RustyWind with a custom config file Source: https://github.com/avencera/rustywind/blob/master/README.md Specify a JSON configuration file using --config-file to define a custom class sort order. ```bash rustywind --config-file config_file.json ``` -------------------------------- ### Variant Extraction Example Source: https://github.com/avencera/rustywind/blob/master/_autodocs/09-sorting-algorithm.md Illustrates how RustyWind decomposes CSS classes into variants and the main utility part. Handles various syntaxes including nested and bracketed variants. ```text md:p-4 → variants: ["md"], utility: "p-4" hover:focus:flex → variants: ["focus", "hover"], utility: "flex" [&>*]:p-4 → variants: ["[&>*]"], utility: "p-4" ``` -------------------------------- ### CLI Integration for Class Wrapping Source: https://github.com/avencera/rustywind/blob/master/_autodocs/06-class-wrapping.md Shows how to use the `--class-wrapping` CLI flag to specify different wrapping formats. The flag accepts string representations of the wrapping variants. ```bash # Space-separated (default) rustywind . --class-wrapping no-wrapping # Comma with single quotes rustywind . --class-wrapping comma-single-quotes # Comma with double quotes rustywind . --class-wrapping comma-double-quotes ``` -------------------------------- ### CommaDoubleQuotes Mode Example Source: https://github.com/avencera/rustywind/blob/master/_autodocs/06-class-wrapping.md Demonstrates sorting classes for TypeScript arrays using `CommaDoubleQuotes` mode. Input and output classes are comma-space separated and enclosed in double quotes. ```rust let app = RustyWind { class_wrapping: ClassWrapping::CommaDoubleQuotes, ..Default::default() }; let classes = r###""p-4", "m-4", "flex""###; let sorted = app.sort_classes(classes); // Output: "\"m-4\", \"flex\", \"p-4\"" ``` -------------------------------- ### Custom Class Wrapping Configuration Source: https://github.com/avencera/rustywind/blob/master/_autodocs/12-architecture.md Illustrates configuring RustyWind with custom class wrapping behavior. ```rust let app = RustyWind { class_wrapping: ClassWrapping::CommaSingleQuotes, ..Default::default() }; ``` -------------------------------- ### CommaSingleQuotes Mode Example Source: https://github.com/avencera/rustywind/blob/master/_autodocs/06-class-wrapping.md Demonstrates sorting classes for JavaScript arrays using `CommaSingleQuotes` mode. Input and output classes are comma-space separated and enclosed in single quotes. ```rust let app = RustyWind { class_wrapping: ClassWrapping::CommaSingleQuotes, ..Default::default() }; let input = "classes = ['p-4', 'm-4', 'flex']"; let output = app.sort_classes("'p-4', 'm-4', 'flex'"); // Output: "'m-4', 'flex', 'p-4'" ``` -------------------------------- ### CompactString for Cache Keys Source: https://github.com/avencera/rustywind/blob/master/_autodocs/12-architecture.md Illustrates using CompactString to minimize heap allocations for typical cache keys. ```rust let class_compact = compact_str::CompactString::new(class); // Most class names fit in 24-byte inline buffer ``` -------------------------------- ### as_str Method for ClassWrapping Source: https://github.com/avencera/rustywind/blob/master/_autodocs/06-class-wrapping.md Gets the string representation of the wrapping mode. Returns one of: "no-wrapping", "comma-single-quotes", "comma-double-quotes". ```rust pub fn as_str(&self) -> &'static str ``` ```rust use rustywind_core::class_wrapping::ClassWrapping; assert_eq!(ClassWrapping::NoWrapping.as_str(), "no-wrapping"); assert_eq!(ClassWrapping::CommaSingleQuotes.as_str(), "comma-single-quotes"); assert_eq!(ClassWrapping::CommaDoubleQuotes.as_str(), "comma-double-quotes"); ``` -------------------------------- ### GitHub Actions for Class Formatting Check Source: https://github.com/avencera/rustywind/blob/master/_autodocs/10-cli-reference.md Set up a GitHub Actions workflow to automatically check if your code is formatted by RustyWind on pull requests. It requires installing RustyWind globally. ```yaml name: Check Class Formatting on: [pull_request] jobs: rustywind: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: npm install -g rustywind - run: rustywind . --check-formatted ``` -------------------------------- ### Rustywind Option: Vite CSS URL Source: https://github.com/avencera/rustywind/blob/master/_autodocs/10-cli-reference.md Fetches CSS from a Vite dev server to determine sort order. Mutually exclusive with --config-file and --output-css-file. Experimental. ```bash rustywind . --vite-css "http://localhost:5173/src/assets/main.css" ``` ```bash # Start Vite dev server npm run dev ``` ```bash # In another terminal, sort with Vite CSS rustywind . --vite-css "http://127.0.0.1:5173/src/assets/main.css" --dry-run ``` -------------------------------- ### Basic RustyWind CLI Usage Source: https://github.com/avencera/rustywind/blob/master/_autodocs/11-code-examples.md Shows fundamental RustyWind CLI commands for sorting classes, including dry-run, in-place modification, targeting specific files, and checking formatting. ```bash # View changes without modifying rustywind . # Modify files in place rustywind . --write # Specific file rustywind src/index.tsx --write # Check if formatted rustywind . --check-formatted ``` -------------------------------- ### Rust Example: Compound Variant with Arbitrary Value Source: https://github.com/avencera/rustywind/blob/master/_autodocs/05-class-parser.md Illustrates parsing a class name that combines a compound variant (e.g., 'group-hover') with an arbitrary value, such as 'group-hover:bg-[#1da1f2]'. ```rust let parsed = parse_class("group-hover:bg-[#1da1f2]").unwrap(); assert_eq!(parsed.variants, vec!["group-hover"]); assert_eq!(parsed.utility, "bg"); assert_eq!(parsed.value, "[#1da1f2]"); ``` -------------------------------- ### Custom Sorter: Class Lookup and Indexing Source: https://github.com/avencera/rustywind/blob/master/_autodocs/09-sorting-algorithm.md Explains the process for the custom sorter: checking for class existence in a HashMap and using the mapped index, with unmapped classes appended. ```text 1. Class lookup: Check if class exists in the HashMap 2. Get index: If found, use mapped index value 3. Not found: Class appears at end in original order ``` -------------------------------- ### Get CSS Properties Source: https://github.com/avencera/rustywind/blob/master/_autodocs/05-class-parser.md Looks up the corresponding CSS properties for a given utility. Returns `None` if the utility is not recognized by Tailwind's internal map, such as custom utility classes. ```rust pub fn get_properties(&self) -> Option<&'static [&'static str]> ``` ```rust let parsed = parse_class("mx-4").unwrap(); let props = parsed.get_properties().unwrap(); assert!(props.contains(&"margin-inline")); let parsed = parse_class("my-custom-class").unwrap(); let props = parsed.get_properties(); assert!(props.is_none()); // Custom classes have no properties ```