Last active
February 1, 2018 00:20
-
-
Save sveetch/a3915baf41a6a83e6888075ab330a3cb to your computer and use it in GitHub Desktop.
Given a string of Sass color variables, output Sass variables for palette, color scheme models for Sveetoy and a Python list of available color names
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
# -*- coding: utf-8 -*- | |
""" | |
Given a string of Sass color variables, output Sass variables for palette, | |
color scheme models and Python list | |
""" | |
import io | |
COLORS_STRING = u""" | |
$black: #000000; | |
$white: #ffffff; | |
$gray19: #303030; | |
$gray22: #3f3f3f; | |
""" | |
colors = [] | |
for item in COLORS_STRING.splitlines(): | |
if item: | |
name, code = item.split(':') | |
name, code = name.strip(), code.strip() | |
name = name[1:] | |
if code.endswith(';'): | |
code = code[:-1] | |
#print(name,code) | |
colors.append((name, code)) | |
# Text color palette init | |
text_palette = io.StringIO() | |
text_palette.write(u'$sv-color-text-palette: (\n') | |
# Scheme color init | |
model_schemes = io.StringIO() | |
# Text color palette init | |
scheme_palette = io.StringIO() | |
scheme_palette.write(u'$sv-colors-schemes: (\n') | |
# Color palette as Python list | |
python_palette = io.StringIO() | |
python_palette.write(u'colors = [\n') | |
# | |
for name,code in colors: | |
text_palette.write(u' {}: ${},\n'.format(name, name)) | |
python_palette.write(u" '{}',\n".format(name)) | |
scheme_palette.write(u' {}: ${}-color-scheme,\n'.format(name, name)) | |
model_schemes.write(u'${}-color-scheme: (\n background: ${},\n);\n\n'.format(name, name)) | |
# Text color palette output | |
text_palette.write(u');\n\n') | |
text_palette_content = text_palette.getvalue() | |
text_palette.close() | |
print(text_palette_content) | |
# Color scheme models output | |
model_schemes_content = model_schemes.getvalue() | |
model_schemes.close() | |
print(model_schemes_content) | |
# Color scheme palette output | |
scheme_palette.write(u');\n\n') | |
scheme_palette_content = scheme_palette.getvalue() | |
scheme_palette.close() | |
print(scheme_palette_content) | |
# Python color palette | |
python_palette.write(u']\n\n') | |
python_palette_content = python_palette.getvalue() | |
python_palette.close() | |
print(python_palette_content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment