Skip to content

Instantly share code, notes, and snippets.

@shapiromatron
Last active December 20, 2015 09:08
Show Gist options
  • Select an option

  • Save shapiromatron/6105189 to your computer and use it in GitHub Desktop.

Select an option

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.
#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