|
1 | | -# CSS2PHP |
| 1 | +# CSS2PHP Converter |
| 2 | + |
| 3 | +A powerful Python tool for converting CSS files and URLs into PHP arrays with advanced parsing and merging capabilities. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +## Key Features |
| 9 | + |
| 10 | +- 🎯 **New: Split Selectors Mode** - Optional splitting of combined CSS selectors |
| 11 | +- 🔄 Convert CSS files/URLs to PHP arrays |
| 12 | +- 📱 Handle media queries & pseudo-classes |
| 13 | +- 🛠️ Auto-fix PHP syntax issues |
| 14 | +- 📊 Detailed statistics & reporting |
| 15 | +- 🔄 Advanced file merging with priority |
| 16 | +- 💾 Customizable output paths |
| 17 | + |
| 18 | +## Installation |
| 19 | + |
| 20 | +```bash |
| 21 | +# Clone repository |
| 22 | +git clone https://github.com/sakibweb/css2php |
| 23 | + |
| 24 | +# Navigate to directory |
| 25 | +cd css2php |
| 26 | + |
| 27 | +# Install dependencies |
| 28 | +pip install -r requirements.txt |
| 29 | +``` |
2 | 30 |
|
3 | 31 | **Convert CSS files/URLs to PHP arrays** |
4 | 32 |
|
|
19 | 47 | * **Merge Functionality:** Capable of merging multiple PHP array files (generated by CSS2PHP) into a single, consolidated file, useful for combining styles from different sources. |
20 | 48 | * **Output Customization:** Allows setting a custom output directory and filename prefix for generated PHP files. |
21 | 49 | * **PHP Syntax Validation & Auto-Fix:** Validates the generated PHP array for syntax errors and attempts to automatically fix common issues, ensuring code correctness. |
| 50 | +* **Split Selectors Mode:** Option to split combined CSS selectors into individual keys in the PHP array. This might be useful in some scenarios but could lead to loss of CSS specificity. Controlled by the `--split-selectors` flag. |
22 | 51 | * **Statistics (Detailed):** Generates in-depth processing statistics, including class counts, compression ratio, media query and pseudo-class detection, and syntax validation status. |
23 | 52 | * **Tailwind CSS Compatibility:** Handles common Tailwind CSS escape patterns in class names for cleaner PHP output. |
24 | 53 | * **Timeout Control:** Sets a timeout for fetching remote CSS files, preventing indefinite hangs. |
@@ -85,6 +114,14 @@ css2php -m -md ./php_output -mn combined_styles |
85 | 114 |
|
86 | 115 | This will merge all PHP files found in the `./php_output` directory and create a merged file named `combined_styles.php` in the `./output` directory. |
87 | 116 |
|
| 117 | +**Splitting CSS Selectors:** |
| 118 | + |
| 119 | +To split combined CSS selectors (like `.class1.class2`) into individual keys: |
| 120 | + |
| 121 | +```bash |
| 122 | +css2php styles.css --split-selectors |
| 123 | +``` |
| 124 | + |
88 | 125 | ## Command-Line Arguments |
89 | 126 |
|
90 | 127 | Here is a list of all available command-line arguments, sorted alphabetically: |
@@ -129,6 +166,10 @@ Here is a list of all available command-line arguments, sorted alphabetically: |
129 | 166 | * **Description:** Instructs CSS2PHP to skip errors encountered during CSS fetching or parsing and continue processing other sources. Warnings will be printed for skipped errors. |
130 | 167 | * **Example:** `css2php styles.css -s` |
131 | 168 |
|
| 169 | +* `--split-selectors`: |
| 170 | + * **Description:** Splits combined CSS selectors into individual keys in the PHP array. |
| 171 | + * **Example:** `css2php styles.css --split-selectors` |
| 172 | + |
132 | 173 | * `-sources` `[SOURCES ...]`: |
133 | 174 | * **Description:** One or more CSS file paths or URLs to convert. This is the primary input for the tool. |
134 | 175 | * **Example:** `css2php styles.css https://example.com/theme.css` |
@@ -176,6 +217,7 @@ CSS2PHP provides detailed reports and statistics for each conversion and merge o |
176 | 217 | * Skip errors (Yes/No) |
177 | 218 | * Timeout (seconds) |
178 | 219 | * Overwrite enabled (Yes/No) |
| 220 | + * Split Selectors (Yes/No) |
179 | 221 | * **File Structure Explanation:** Describes the structure of the generated PHP array. |
180 | 222 |
|
181 | 223 | **For merge operations, the report includes:** |
|
0 commit comments