Last active
February 6, 2024 15:21
-
-
Save pagelab/26143abb6d2f8dd8d104d15ce4a582d3 to your computer and use it in GitHub Desktop.
Script to convert a list of CSS custom properties to the JSON format required by Advanced Themer to make them appear on the Bricks Builder fields (via the “V” symbol).
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
# Script to convert a list of CSS custom properties to the JSON format required by Advanced Themer to make them appear on the Bricks Builder fields (via the “V” symbol). | |
# 1. Add a file in a folder with all CSS variables from Core Framework called core-framework-css-variables.css, one per line. Group each section using CSS comments. | |
# 2. Run the python script to generate the JSON file for Advanced Themer: python3 convert-css-variables-to-json.py | |
# 3. Add the file to the “Import Framework” option of the Advanced Themer on Bricks → AT - Theme settints → Global CSS Variables → Import Framework. | |
import re | |
import json | |
# Read the CSS file | |
with open('core-framework-css-variables.css', 'r') as f: | |
css = f.readlines() | |
# Find all section titles and properties | |
sections = {} | |
current_section = "" | |
for line in css: | |
if line.strip().startswith("/*") and line.strip().endswith("*/"): | |
current_section = line.strip()[2:-2] | |
sections[current_section] = [] | |
elif line.strip().startswith("--"): | |
sections[current_section].append(re.search(r"--(.+?)(?=\:)", line).group(1)) | |
# Output in desired JSON structure | |
with open('core-framework-css-variables.json', 'w') as f: f.write(json.dumps(sections, indent=4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the actual file I use: