Home / File/ slim.rs — tailwindcss Source File

slim.rs — tailwindcss Source File

Architecture documentation for slim.rs, a rust file in the tailwindcss codebase. 6 imports, 0 dependents.

File rust OxideEngine PreProcessors 6 imports 8 functions

Entity Profile

Dependency Diagram

graph LR
  728c6622_d993_001c_2e5b_541b85f1c521["slim.rs"]
  a9917971_bc7e_dd9a_6dd4_d2fae5ab1c29["super::Slim"]
  728c6622_d993_001c_2e5b_541b85f1c521 --> a9917971_bc7e_dd9a_6dd4_d2fae5ab1c29
  e4e20bdf_ad1e_e4a0_5cba_d0f5a5db787e["crate::cursor"]
  728c6622_d993_001c_2e5b_541b85f1c521 --> e4e20bdf_ad1e_e4a0_5cba_d0f5a5db787e
  94b5420b_055c_efe5_392d_b0d15e43aa35["crate::extractor::bracket_stack::BracketStack"]
  728c6622_d993_001c_2e5b_541b85f1c521 --> 94b5420b_055c_efe5_392d_b0d15e43aa35
  cd83abb6_a664_e16d_ddc8_60a3f23ba86a["crate::extractor::machine::"]
  728c6622_d993_001c_2e5b_541b85f1c521 --> cd83abb6_a664_e16d_ddc8_60a3f23ba86a
  a55fec3d_3fee_4b46_48f2_43f3844c61e4["crate::extractor::pre_processors::pre_processor::PreProcessor"]
  728c6622_d993_001c_2e5b_541b85f1c521 --> a55fec3d_3fee_4b46_48f2_43f3844c61e4
  71141c85_3e46_c613_7ae6_deef432b10a2["crate::extractor::variant_machine::VariantMachine"]
  728c6622_d993_001c_2e5b_541b85f1c521 --> 71141c85_3e46_c613_7ae6_deef432b10a2
  style 728c6622_d993_001c_2e5b_541b85f1c521 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

use crate::cursor;
use crate::extractor::bracket_stack::BracketStack;
use crate::extractor::machine::{Machine, MachineState};
use crate::extractor::pre_processors::pre_processor::PreProcessor;
use crate::extractor::variant_machine::VariantMachine;

#[derive(Debug, Default)]
pub struct Slim;

impl PreProcessor for Slim {
    fn process(&self, content: &[u8]) -> Vec<u8> {
        let len = content.len();
        let mut result = content.to_vec();
        let mut cursor = cursor::Cursor::new(content);
        let mut bracket_stack = BracketStack::default();

        while cursor.pos < len {
            match cursor.curr {
                // Only replace `.` with a space if it's not surrounded by numbers. E.g.:
                //
                // ```diff
                // - .flex.items-center
                // +  flex items-center
                // ```
                //
                // But with numbers, it's allowed:
                //
                // ```diff
                // - px-2.5
                // + px-2.5
                // ```
                b'.' => {
                    // Don't replace dots with spaces when inside of any type of brackets, because
                    // this could be part of arbitrary values. E.g.: `bg-[url(https://example.com)]`
                    //                                                                       ^
                    if !bracket_stack.is_empty() {
                        cursor.advance();
                        continue;
                    }

                    // If the dot is surrounded by digits, we want to keep it. E.g.: `px-2.5`
                    // EXCEPT if it's followed by a valid variant that happens to start with a
                    // digit.
                    // E.g.: `bg-red-500.2xl:flex`
                    //                 ^^^
                    if cursor.prev.is_ascii_digit() && cursor.next.is_ascii_digit() {
                        let mut next_cursor = cursor.clone();
                        next_cursor.advance();

                        let mut variant_machine = VariantMachine::default();
                        if let MachineState::Done(_) = variant_machine.next(&mut next_cursor) {
                            result[cursor.pos] = b' ';
                        }
                    } else {
                        result[cursor.pos] = b' ';
                    }
                }

                // Handle Ruby syntax with `%w[]` arrays embedded in Slim directly.
                //
// ... (272 more lines)

Domain

Subdomains

Dependencies

  • crate::cursor
  • crate::extractor::bracket_stack::BracketStack
  • crate::extractor::machine::
  • crate::extractor::pre_processors::pre_processor::PreProcessor
  • crate::extractor::variant_machine::VariantMachine
  • super::Slim

Frequently Asked Questions

What does slim.rs do?
slim.rs is a source file in the tailwindcss codebase, written in rust. It belongs to the OxideEngine domain, PreProcessors subdomain.
What functions are defined in slim.rs?
slim.rs defines 8 function(s): process, test_arbitrary_code_followed_by_classes, test_class_shorthand_followed_by_parens, test_embedded_ruby_percent_w_extraction, test_nested_slim_syntax, test_single_quotes_to_enforce_trailing_whitespace, test_slim_pre_processor, test_strings_only_occur_when_nested.
What does slim.rs depend on?
slim.rs imports 6 module(s): crate::cursor, crate::extractor::bracket_stack::BracketStack, crate::extractor::machine::, crate::extractor::pre_processors::pre_processor::PreProcessor, crate::extractor::variant_machine::VariantMachine, super::Slim.
Where is slim.rs in the architecture?
slim.rs is located at crates/oxide/src/extractor/pre_processors/slim.rs (domain: OxideEngine, subdomain: PreProcessors, directory: crates/oxide/src/extractor/pre_processors).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free