Home / Function/ process() — tailwindcss Function Reference

process() — tailwindcss Function Reference

Architecture documentation for the process() function in ruby.rs from the tailwindcss codebase.

Entity Profile

Dependency Diagram

graph TD
  1916f555_a863_9e22_fc38_d0f5bf0b5696["process()"]
  435a321a_a1e2_cb4f_7579_0ca15cb86434["advance()"]
  1916f555_a863_9e22_fc38_d0f5bf0b5696 -->|calls| 435a321a_a1e2_cb4f_7579_0ca15cb86434
  07207bb0_f195_4067_2024_eb12d4800851["advance_twice()"]
  1916f555_a863_9e22_fc38_d0f5bf0b5696 -->|calls| 07207bb0_f195_4067_2024_eb12d4800851
  b48fd729_f8f3_6be8_edce_61b153fa877e["reset()"]
  1916f555_a863_9e22_fc38_d0f5bf0b5696 -->|calls| b48fd729_f8f3_6be8_edce_61b153fa877e
  2c3dea25_8534_307e_ed29_9da5e42908c7["push()"]
  1916f555_a863_9e22_fc38_d0f5bf0b5696 -->|calls| 2c3dea25_8534_307e_ed29_9da5e42908c7
  a6cec50b_244a_1320_58e6_036228829a18["is_empty()"]
  1916f555_a863_9e22_fc38_d0f5bf0b5696 -->|calls| a6cec50b_244a_1320_58e6_036228829a18
  97d3f6aa_a90c_02b6_d13e_9bea2e7ae659["pop()"]
  1916f555_a863_9e22_fc38_d0f5bf0b5696 -->|calls| 97d3f6aa_a90c_02b6_d13e_9bea2e7ae659
  style 1916f555_a863_9e22_fc38_d0f5bf0b5696 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

crates/oxide/src/extractor/pre_processors/ruby.rs lines 29–222

    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 = bracket_stack::BracketStack::default();

        // Extract embedded template languages
        // https://viewcomponent.org/guide/templates.html#interpolations
        let content_as_str = std::str::from_utf8(content).unwrap();

        let starts = TEMPLATE_START_REGEX
            .captures_iter(content_as_str)
            .collect::<Vec<_>>();
        let ends = TEMPLATE_END_REGEX
            .captures_iter(content_as_str)
            .collect::<Vec<_>>();

        for start in starts.iter() {
            // The language for this block
            let lang = start.get(1).unwrap().as_str();

            // The HEREDOC delimiter
            let delimiter_start = start.get(2).unwrap().as_str();

            // Where the "body" starts for the HEREDOC block
            let body_start = start.get(0).unwrap().end();

            // Look through all of the ends to find a matching language
            for end in ends.iter() {
                // 1. This must appear after the start
                let body_end = end.get(0).unwrap().start();
                if body_end < body_start {
                    continue;
                }

                // The languages must match otherwise we haven't found the end
                let delimiter_end = end.get(1).unwrap().as_str();
                if delimiter_end != delimiter_start {
                    continue;
                }

                let body = &content_as_str[body_start..body_end];
                let replaced = pre_process_input(body.as_bytes(), &lang.to_ascii_lowercase());

                result.replace_range(body_start..body_end, replaced);
                break;
            }
        }

        // Ruby extraction
        while cursor.pos < len {
            match cursor.curr {
                b'"' => {
                    cursor.advance();

                    while cursor.pos < len {
                        match cursor.curr {
                            // Escaped character, skip ahead to the next character
                            b'\\' => cursor.advance_twice(),

                            // End of the string
                            b'"' => break,

                            // Everything else is valid
                            _ => cursor.advance(),
                        };
                    }

                    cursor.advance();
                    continue;
                }

                b'\'' => {
                    cursor.advance();

                    while cursor.pos < len {
                        match cursor.curr {
                            // Escaped character, skip ahead to the next character
                            b'\\' => cursor.advance_twice(),

                            // End of the string
                            b'\'' => break,

                            // Everything else is valid
                            _ => cursor.advance(),
                        };
                    }

                    cursor.advance();
                    continue;
                }

                // Replace comments in Ruby files
                //
                // Except for strict locals, these are defined in a `<%# locals: … %>`. Checking if
                // the comment is preceded by a `%` should be enough without having to perform more
                // parsing logic. Worst case we _do_ scan a few comments.
                b'#' if !matches!(cursor.prev, b'%') => {
                    result[cursor.pos] = b' ';
                    cursor.advance();

                    while cursor.pos < len {
                        match cursor.curr {
                            // End of the comment
                            b'\n' => break,

                            // Everything else is part of the comment and replaced
                            _ => {
                                result[cursor.pos] = b' ';
                                cursor.advance();
                            }
                        };
                    }

                    cursor.advance();
                    continue;
                }

                _ => {}
            }

            // Looking for `%w`, `%W`, or `%p`
            if cursor.curr != b'%' || !matches!(cursor.next, b'w' | b'W' | b'p') {
                cursor.advance();
                continue;
            }

            cursor.advance_twice();

            // Boundary character
            let boundary = match cursor.curr {
                b'[' => b']',
                b'(' => b')',
                b'{' => b'}',
                b'#' => b'#',
                b' ' => b'\n',
                _ => {
                    cursor.advance();
                    continue;
                }
            };

            bracket_stack.reset();

            // Replace the current character with a space
            result[cursor.pos] = b' ';

            // Skip the boundary character
            cursor.advance();

            while cursor.pos < len {
                match cursor.curr {
                    // Skip escaped characters
                    b'\\' => {
                        // Use backslash to embed spaces in the strings.
                        if cursor.next == b' ' {
                            result[cursor.pos] = b' ';
                        }

                        cursor.advance();
                    }

                    // Start of a nested bracket
                    b'[' | b'(' | b'{' => {
                        bracket_stack.push(cursor.curr);
                    }

                    // End of a nested bracket
                    b']' | b')' | b'}' if !bracket_stack.is_empty() => {
                        if !bracket_stack.pop(cursor.curr) {
                            // Unbalanced
                            cursor.advance();
                        }
                    }

                    // End of the pattern, replace the boundary character with a space
                    _ if cursor.curr == boundary => {
                        if boundary != b'\n' {
                            result[cursor.pos] = b' ';
                        }

                        break;
                    }

                    // Everything else is valid
                    _ => {}
                }

                cursor.advance();
            }
        }

        result
    }

Domain

Subdomains

Frequently Asked Questions

What does process() do?
process() is a function in the tailwindcss codebase.
What does process() call?
process() calls 6 function(s): advance, advance_twice, is_empty, pop, push, reset.

Analyze Your Own Codebase

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

Try Supermodel Free