Skip to content

Instantly share code, notes, and snippets.

@cpdean
Last active December 31, 2015 02:39
Show Gist options
  • Save cpdean/7922488 to your computer and use it in GitHub Desktop.
Save cpdean/7922488 to your computer and use it in GitHub Desktop.
put CSS files next to this and find redundant rules. maybe you can use that to guide yourself in an OOCSS refactor

With the power of bash piping and a tiny python script you can see what css rules could stand to be merged into simple classes.

#/bin/sh
cat *css | python properties.py | sort | uniq -c | sort -n
# parse out the css properties that are piped in
import tinycss
import sys
parser = tinycss.make_parser("page3")
parsed = parser.parse_stylesheet_file(sys.stdin)
for r in parsed.rules:
for d in r.declarations:
try:
print d.name + ": " + d.value.as_css()
except UnicodeEncodeError as e:
pass # fuckit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment