Created
October 12, 2023 08:00
-
-
Save merianos/0ba9f12b6f643bc1a092b2363f88867b to your computer and use it in GitHub Desktop.
Convert Pollen CSS to Bricks JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$css = file_get_contents(dirname(__FILE__) . '/pollen.css'); | |
$css = preg_replace( | |
[ | |
"/\/\*\*[^\/]*\//m", // Remove any comments | |
"/\:root\s*\{/", // Remove :root { | |
"/\}/", // Remove trailing } | |
"/\n\s*\n/m", // Remove any empty lines | |
"/^\s*/m", // remove empty spaces from the front end of variables | |
"/\:\s*[^\n]+/m" // Remove the value part of the variables (: value) | |
], | |
'', | |
$css | |
); | |
$css = array_map( | |
function($variable) { | |
$variable = str_replace("--", '', $variable); | |
$variable_parts = explode('-', $variable); | |
$category = array_shift($variable_parts); | |
return [ | |
'category' => $category, | |
'variable' => $variable | |
]; | |
}, | |
explode("\n", $css) | |
); | |
$output_array = []; | |
foreach($css as $entry) { | |
$output_array[$entry['category']][] = $entry['variable']; | |
} | |
file_put_contents(dirname(__FILE__) . '/pollen.json', json_encode($output_array, JSON_PRETTY_PRINT)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment