Skip to content

Instantly share code, notes, and snippets.

@merianos
Created October 12, 2023 08:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save merianos/0ba9f12b6f643bc1a092b2363f88867b to your computer and use it in GitHub Desktop.
Save merianos/0ba9f12b6f643bc1a092b2363f88867b to your computer and use it in GitHub Desktop.
Convert Pollen CSS to Bricks JSON
<?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