pug.rs — tailwindcss Source File
Architecture documentation for pug.rs, a rust file in the tailwindcss codebase. 6 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 3983a944_71de_6013_6287_530db068a263["pug.rs"] 4e006ac5_40ec_eb0e_fe09_5735bf785606["super::Pug"] 3983a944_71de_6013_6287_530db068a263 --> 4e006ac5_40ec_eb0e_fe09_5735bf785606 e4e20bdf_ad1e_e4a0_5cba_d0f5a5db787e["crate::cursor"] 3983a944_71de_6013_6287_530db068a263 --> e4e20bdf_ad1e_e4a0_5cba_d0f5a5db787e 94b5420b_055c_efe5_392d_b0d15e43aa35["crate::extractor::bracket_stack::BracketStack"] 3983a944_71de_6013_6287_530db068a263 --> 94b5420b_055c_efe5_392d_b0d15e43aa35 cd83abb6_a664_e16d_ddc8_60a3f23ba86a["crate::extractor::machine::"] 3983a944_71de_6013_6287_530db068a263 --> cd83abb6_a664_e16d_ddc8_60a3f23ba86a a55fec3d_3fee_4b46_48f2_43f3844c61e4["crate::extractor::pre_processors::pre_processor::PreProcessor"] 3983a944_71de_6013_6287_530db068a263 --> a55fec3d_3fee_4b46_48f2_43f3844c61e4 71141c85_3e46_c613_7ae6_deef432b10a2["crate::extractor::variant_machine::VariantMachine"] 3983a944_71de_6013_6287_530db068a263 --> 71141c85_3e46_c613_7ae6_deef432b10a2 style 3983a944_71de_6013_6287_530db068a263 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
Functions
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
Source
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 OxideEngine 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: 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