Skip to content

Instantly share code, notes, and snippets.

@pagelab
Last active June 22, 2024 12:34
Show Gist options
  • Save pagelab/26143abb6d2f8dd8d104d15ce4a582d3 to your computer and use it in GitHub Desktop.
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).
# 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))
@FinalLightNL
Copy link

Isn't there a way to automate this a bit?
what exactly do i need to comment in css, cuz the framework has root and colors in it and colors outside of it among other things.

@pagelab
Copy link
Author

pagelab commented Feb 6, 2024

Isn't there a way to automate this a bit? what exactly do i need to comment in css, cuz the framework has root and colors in it and colors outside of it among other things.

This is the actual file I use:

/*Primary colors*/
--primary: hsl(238, 100%, 62%);
--primary-5: hsla(238, 100%, 62%, 0.05);
--primary-10: hsla(238, 100%, 62%, 0.1);
--primary-20: hsla(238, 100%, 62%, 0.2);
--primary-30: hsla(238, 100%, 62%, 0.3);
--primary-40: hsla(238, 100%, 62%, 0.4);
--primary-50: hsla(238, 100%, 62%, 0.5);
--primary-60: hsla(238, 100%, 62%, 0.6);
--primary-70: hsla(238, 100%, 62%, 0.7);
--primary-80: hsla(238, 100%, 62%, 0.8);
--primary-90: hsla(238, 100%, 62%, 0.9);
--primary-d-1: hsl(240, 56%, 50%);
--primary-d-2: hsl(243, 54%, 37%);
--primary-d-3: hsl(246, 51%, 25%);
--primary-d-4: hsl(250, 43%, 13%);
--primary-l-1: hsl(247, 100%, 70%);
--primary-l-2: hsl(251, 100%, 77%);
--primary-l-3: hsl(254, 100%, 85%);
--primary-l-4: hsl(256, 100%, 92%);

/*Secondary colors*/
--secondary: hsl(0, 94%, 68%);
--secondary-5: hsla(0, 94%, 68%, 0.05);
--secondary-10: hsla(0, 94%, 68%, 0.1);
--secondary-20: hsla(0, 94%, 68%, 0.2);
--secondary-30: hsla(0, 94%, 68%, 0.3);
--secondary-40: hsla(0, 94%, 68%, 0.4);
--secondary-50: hsla(0, 94%, 68%, 0.5);
--secondary-60: hsla(0, 94%, 68%, 0.6);
--secondary-70: hsla(0, 94%, 68%, 0.7);
--secondary-80: hsla(0, 94%, 68%, 0.8);
--secondary-90: hsla(0, 94%, 68%, 0.9);
--secondary-d-1: hsl(1, 50%, 53%);
--secondary-d-2: hsl(1, 42%, 40%);
--secondary-d-3: hsl(2, 40%, 26%);
--secondary-d-4: hsl(4, 35%, 14%);
--secondary-l-1: hsl(3, 100%, 75%);
--secondary-l-2: hsl(5, 100%, 81%);
--secondary-l-3: hsl(6, 100%, 87%);
--secondary-l-4: hsl(7, 100%, 93%);

/*Tertiary colors*/
--tertiary: hsl(198, 74%, 51%);
--tertiary-5: hsla(198, 74%, 51%, 0.05);
--tertiary-10: hsla(198, 74%, 51%, 0.1);
--tertiary-20: hsla(198, 74%, 51%, 0.2);
--tertiary-30: hsla(198, 74%, 51%, 0.3);
--tertiary-40: hsla(198, 74%, 51%, 0.4);
--tertiary-50: hsla(198, 74%, 51%, 0.5);
--tertiary-60: hsla(198, 74%, 51%, 0.6);
--tertiary-70: hsla(198, 74%, 51%, 0.7);
--tertiary-80: hsla(198, 74%, 51%, 0.8);
--tertiary-90: hsla(198, 74%, 51%, 0.9);
--tertiary-d-1: hsl(199, 63%, 42%);
--tertiary-d-2: hsl(200, 55%, 32%);
--tertiary-d-3: hsl(201, 46%, 22%);
--tertiary-d-4: hsl(203, 35%, 13%);
--tertiary-l-1: hsl(202, 71%, 65%);
--tertiary-l-2: hsl(203, 70%, 75%);
--tertiary-l-3: hsl(204, 70%, 84%);
--tertiary-l-4: hsl(205, 70%, 92%);

/*Extra colors*/
--bg-body: hsla(0, 0%, 90%, 1);
--bg-surface: hsla(0, 0%, 100%, 1);
--text-body: hsla(0, 0%, 25%, 1);
--text-title: hsla(0, 0%, 0%, 1);
--border-primary: hsla(0, 0%, 50%, 0.25);
--shadow-primary: hsla(0, 0%, 0%, 0.15);
--light: hsl(85, 0%, 100%);
--light-5: hsla(0, 0%, 100%, 0.05);
--light-10: hsla(0, 0%, 100%, 0.1);
--light-20: hsla(0, 0%, 100%, 0.2);
--light-30: hsla(0, 0%, 100%, 0.3);
--light-40: hsla(0, 0%, 100%, 0.4);
--light-50: hsla(0, 0%, 100%, 0.5);
--light-60: hsla(0, 0%, 100%, 0.6);
--light-70: hsla(0, 0%, 100%, 0.7);
--light-80: hsla(0, 0%, 100%, 0.8);
--light-90: hsla(0, 0%, 100%, 0.9);
--dark: hsla(0, 0%, 0%, 1);
--dark-5: hsla(0, 0%, 0%, 0.05);
--dark-10: hsla(0, 0%, 0%, 0.1);
--dark-20: hsla(0, 0%, 0%, 0.2);
--dark-30: hsla(0, 0%, 0%, 0.3);
--dark-40: hsla(0, 0%, 0%, 0.4);
--dark-50: hsla(0, 0%, 0%, 0.5);
--dark-60: hsla(0, 0%, 0%, 0.6);
--dark-70: hsla(0, 0%, 0%, 0.7);
--dark-80: hsla(0, 0%, 0%, 0.8);
--dark-90: hsla(0, 0%, 0%, 0.9);
--success: hsl(136, 95%, 56%);
--success-5: hsla(136, 95%, 56%, 0.05);
--success-10: hsla(136, 95%, 56%, 0.1);
--success-20: hsla(136, 95%, 56%, 0.2);
--success-30: hsla(136, 95%, 56%, 0.3);
--success-40: hsla(136, 95%, 56%, 0.4);
--success-50: hsla(136, 95%, 56%, 0.5);
--success-60: hsla(136, 95%, 56%, 0.6);
--success-70: hsla(136, 95%, 56%, 0.7);
--success-80: hsla(136, 95%, 56%, 0.8);
--success-90: hsla(136, 95%, 56%, 0.9);
--error: hsl(351, 95%, 56%);
--error-5: hsla(351, 95%, 56%, 0.05);
--error-10: hsla(351, 95%, 56%, 0.1);
--error-20: hsla(351, 95%, 56%, 0.2);
--error-30: hsla(351, 95%, 56%, 0.3);
--error-40: hsla(351, 95%, 56%, 0.4);
--error-50: hsla(351, 95%, 56%, 0.5);
--error-60: hsla(351, 95%, 56%, 0.6);
--error-70: hsla(351, 95%, 56%, 0.7);
--error-80: hsla(351, 95%, 56%, 0.8);
--error-90: hsla(351, 95%, 56%, 0.9);

/*Spacing*/
--space-4xs: clamp(0.52rem, calc(-0.03vw + 0.53rem), 0.49rem);
--space-3xs: clamp(0.66rem, calc(0.04vw + 0.64rem), 0.7rem);
--space-2xs: clamp(0.82rem, calc(0.16vw + 0.77rem), 0.99rem);
--space-xs: clamp(1.02rem, calc(0.35vw + 0.91rem), 1.4rem);
--space-s: clamp(1.28rem, calc(0.65vw + 1.07rem), 1.98rem);
--space-m: clamp(1.6rem, calc(1.11vw + 1.24rem), 2.8rem);
--space-l: clamp(2rem, calc(1.81vw + 1.42rem), 3.96rem);
--space-xl: clamp(2.5rem, calc(2.87vw + 1.58rem), 5.6rem);
--space-2xl: clamp(3.13rem, calc(4.44vw + 1.71rem), 7.92rem);
--space-3xl: clamp(3.91rem, calc(6.75vw + 1.75rem), 11.19rem);
--space-4xl: clamp(4.88rem, calc(10.13vw + 1.64rem), 15.83rem);

/*Typography*/
--text-xs: clamp(1.26rem, calc(-0.23vw + 1.34rem), 1.01rem);
--text-s: clamp(1.42rem, calc(-0.07vw + 1.44rem), 1.35rem);
--text-m: clamp(1.6rem, calc(0.19vw + 1.54rem), 1.8rem);
--text-l: clamp(1.8rem, calc(0.55vw + 1.62rem), 2.4rem);
--text-xl: clamp(2.02rem, calc(1.09vw + 1.68rem), 3.2rem);
--text-2xl: clamp(2.28rem, calc(1.84vw + 1.69rem), 4.26rem);
--text-3xl: clamp(2.56rem, calc(2.89vw + 1.64rem), 5.68rem);
--text-4xl: clamp(2.88rem, calc(4.34vw + 1.49rem), 7.58rem);

/*Border radius*/
--radius-xs: clamp(4px, calc(0vw + 4px), 4px);
--radius-s: clamp(6px, calc(-0.19vw + 8.59px), 8px);
--radius-m: clamp(10px, calc(-0.19vw + 12.59px), 12px);
--radius-l: clamp(16px, calc(-0.37vw + 21.19px), 20px);
--radius-xl: clamp(26px, calc(-0.56vw + 33.78px), 32px);
--radius-full: 999rem;

/*Box shadow*/
--shadow-xs: 0 1px 2px var(--shadow-primary);
--shadow-s: 0 1.5px 3px var(--shadow-primary);
--shadow-m: 0 2px 6px var(--shadow-primary);
--shadow-l: 0 3px 12px var(--shadow-primary);
--shadow-xl: 0 6px 48px var(--shadow-primary);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment