Last active
December 20, 2015 09:08
-
-
Save shapiromatron/6105189 to your computer and use it in GitHub Desktop.
Prepares one CSS stylesheet for all styles which may be applied to D3 objects.
This file contains hidden or 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
| #usr/bin/python | |
| import os | |
| import re | |
| this_path = os.path.abspath(__file__) | |
| static_path = os.path.abspath(os.path.join(this_path, r'../../project/static')) | |
| def remove_spacing(txt, character): | |
| txt = re.sub(character + ' ', character, txt) | |
| return re.sub(' ' + character, character, txt) | |
| files = ['css/d3.css', 'css/styles.css', 'css/bootstrap-2.2.2.css'] | |
| txt = '' | |
| for fn in files: | |
| with open(os.path.join(static_path, fn), 'r') as f: | |
| txt = txt + f.read() + ' ' | |
| txt = re.sub(r'\/\*[^(\*\/)]+\*\/', ' ', txt) | |
| txt = re.sub(r'\n', ' ', txt) | |
| txt = re.sub(r' >', ' ', txt) # this style-type can break illustrator | |
| txt = re.sub(r'[ ]+', ' ', txt) | |
| txt = remove_spacing(txt, ":") | |
| txt = remove_spacing(txt, "{") | |
| txt = remove_spacing(txt, "}") | |
| txt = remove_spacing(txt, ";") | |
| txt = re.sub(r'}', r'}\n', txt) | |
| with open(os.path.join(static_path, 'css/d3_styles_aggregated.css'), 'w') as f: | |
| f.write(txt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment