LocalTailwindExtractor Tailwind Templates

Localtailwindextractor

Extract and categorize Tailwind CSS components from PHP projects. Scans your PHP/HTML files and generates a comprehensive library of reusable Tailwind elements.

LocalTailwindExtractor

A powerful Python tool that scans PHP projects and extracts Tailwind CSS components for easy reuse and reference.

Features

  • Extracts Tailwind components from PHP and HTML files
  • Categorizes components by type (buttons, cards, forms, etc.)
  • Eliminates duplicates using structural fingerprinting
  • Supports static analysis of PHP files without execution
  • Optional PHP execution to capture dynamically generated HTML
  • Multi-threaded processing for faster extraction
  • Clean, organized output in an easy-to-reference format

Requirements

  • Python 3.6 or higher
  • BeautifulSoup4 library
  • (Optional) PHP CLI for dynamic content extraction

Installation

Clone this repository: git clone https://github.com/guleyc/LocalTailwindExtractor.git cd LocalTailwindExtractor

Install required dependencies: pip install beautifulsoup4

Quick Start

Basic usage: python local_tailwind_extractor.py /path/to/your/project

This will scan all PHP and HTML files in your project directory and create a tailwind_components.txt file containing all found Tailwind components.

Usage Options

python local_tailwind_extractor.py [project_directory] [options]

Command Line Arguments

Option Description
project_dir Path to the project directory (required)
--output, -o Output file name (default: tailwind_components.txt)
--execute-php, -e Enable PHP execution for dynamic content (disabled by default)
--php-path, -p Path to PHP executable (default: "php")
--threads, -t Number of threads for parallel processing (default: 4)
--quiet, -q Suppress detailed output messages

Examples

Extract with PHP execution enabled: python local_tailwind_extractor.py /path/to/project --execute-php

Specify output file and increase thread count: python local_tailwind_extractor.py /path/to/project --output=my_components.txt --threads=8

Use specific PHP executable: python local_tailwind_extractor.py /path/to/project --execute-php --php-path=/usr/bin/php7.4

Output Format

The tool generates a text file with categorized Tailwind components:

TAILWIND COMPONENTS FROM project_name
Extraction Date: 2025-03-25 23:47:31 Generated by: guleyc

Files scanned: 347 PHP files found: 286 PHP files executed: 42 HTML files found: 12 Total elements found: 1287 Unique elements: 412 Duplicate elements: 875
BUTTONS (42 elements)
Element #1 from includes/components/buttons.php <button class="px-4 py-2 font-bold text-white bg-blue-500 rounded hover:bg-blue-700"> Click me </button>

How It Works

The extraction process follows these steps:

File Discovery: Scans project directory for PHP and HTML files

HTML Extraction: Uses static analysis and optional PHP execution

Component Identification: Identifies elements with Tailwind classes

Structural Hashing: Eliminates duplicate components

Smart Categorization: Organizes components by type

Output Generation: Creates a comprehensive reference file

Component Categories

The extractor automatically categorizes components into these groups:

  • Buttons: Button elements and elements with button-like classes
  • Cards: Card-like container elements, often with images and text
  • Forms: Form elements and their input fields
  • Headers: Page and section header elements
  • Navbars: Navigation bars and menu components
  • Tables: Data tables and tabular layouts
  • Containers: Wrapper and container elements
  • Grids: Grid and flexbox layout systems
  • Inputs: Form input elements and controls
  • Footers: Page and section footer elements
  • Sections: Content section blocks
  • Links: Anchor tags and link elements
  • Other: Miscellaneous components that don't fit other categories

Advanced Usage

Handling Large Projects

For very large projects, you may want to limit thread count and disable PHP execution: python local_tailwind_extractor.py /path/to/large/project --threads=2 --output=large_project_components.txt

Debugging PHP Execution

If you encounter issues with PHP execution, you can check the error output: python local_tailwind_extractor.py /path/to/project --execute-php --php-path=/path/to/php 2> php_errors.log

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Top categories

Loading Svelte Themes