Home / File/ pug.rs — tailwindcss Source File

pug.rs — tailwindcss Source File

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

File rust Oxide PreProcessors 6 imports 5 functions

Entity Profile

Dependency Diagram

graph LR
  ef660f09_55dc_9359_d9d2_abe4a9db93b0["pug.rs"]
  7662814e_ca40_123b_c749_ee6f7f328c80["super::Pug"]
  ef660f09_55dc_9359_d9d2_abe4a9db93b0 --> 7662814e_ca40_123b_c749_ee6f7f328c80
  96a36755_a007_15e1_ec6c_526c02d24b9b["crate::cursor"]
  ef660f09_55dc_9359_d9d2_abe4a9db93b0 --> 96a36755_a007_15e1_ec6c_526c02d24b9b
  c4d29b89_2191_f275_13fb_7cf117340055["crate::extractor::bracket_stack::BracketStack"]
  ef660f09_55dc_9359_d9d2_abe4a9db93b0 --> c4d29b89_2191_f275_13fb_7cf117340055
  05907c18_a40e_a5a9_c7c3_5faba98e1e87["crate::extractor::machine::"]
  ef660f09_55dc_9359_d9d2_abe4a9db93b0 --> 05907c18_a40e_a5a9_c7c3_5faba98e1e87
  ed5b6564_5e78_f7bf_cdc6_b0150d9116c1["crate::extractor::pre_processors::pre_processor::PreProcessor"]
  ef660f09_55dc_9359_d9d2_abe4a9db93b0 --> ed5b6564_5e78_f7bf_cdc6_b0150d9116c1
  087ad9fa_43e6_1338_b489_014631bd4014["crate::extractor::variant_machine::VariantMachine"]
  ef660f09_55dc_9359_d9d2_abe4a9db93b0 --> 087ad9fa_43e6_1338_b489_014631bd4014
  style ef660f09_55dc_9359_d9d2_abe4a9db93b0 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 Pug;

impl PreProcessor for Pug {
    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' ';
                    }
                }

                // In Pug the class name shorthand can be followed by a parenthesis. E.g.:
                //
// ... (122 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::Pug

Frequently Asked Questions

What does pug.rs do?
pug.rs is a source file in the tailwindcss codebase, written in rust. It belongs to the Oxide domain, PreProcessors subdomain.
What functions are defined in pug.rs?
pug.rs defines 5 function(s): process, test_arbitrary_code_followed_by_classes, test_class_shorthand_followed_by_parens, test_pug_pre_processor, test_strings_only_occur_when_nested.
What does pug.rs depend on?
pug.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::Pug.
Where is pug.rs in the architecture?
pug.rs is located at crates/oxide/src/extractor/pre_processors/pug.rs (domain: Oxide, 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