From 60579ab8d0b9be29f6ccb7701dc5fbea614fabe9 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Tue, 24 Jul 2012 21:41:58 -0400 Subject: [PATCH] UglifyCSS as well. --- README.md | 1 + build.py | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index deff407..81a7111 100644 --- a/README.md +++ b/README.md @@ -11,3 +11,4 @@ Dependencies * [mako](http://www.makotemplates.org/) * [oursql](http://packages.python.org/oursql/) * [uglifyjs](https://github.com/mishoo/UglifyJS/) +* [uglifycss](https://github.com/fmarcia/UglifyCSS/) diff --git a/build.py b/build.py index bb492f2..6c1d96f 100755 --- a/build.py +++ b/build.py @@ -58,6 +58,13 @@ class Builder(object): self.root.addHandler(handler) self.root.setLevel(logging.DEBUG) + def _replace_file(self, name, program, logger): + logger.debug("{0} {1}".format(program, name)) + replacement = subprocess.check_output([program, name]) + os.remove(name) + with open(name, "w") as fp: + fp.write(replacement) + def _gen_page(self, page, base): if not page.endswith(".mako"): base.warn("Skipping {0} (not endswith('.mako'))".format(page)) @@ -98,13 +105,11 @@ class Builder(object): shutil.copytree(self.static_dir, dest) for dirpath, dirnames, filenames in os.walk(dest): for filename in filenames: - if filename.endswith(".js"): - name = os.path.join(dirpath, filename) - logger.debug("uglifyjs {0}".format(name)) - uglified = subprocess.check_output(["uglifyjs", name]) - os.remove(name) - with open(name, "w") as fp: - fp.write(uglified) + name = os.path.join(dirpath, filename) + if name.endswith(".js"): + self._replace_file(name, "uglifyjs", logger) + elif name.endswith(".css"): + self._replace_file(name, "uglifycss", logger) def gen_pages(self): logger = self.root.getChild("pages")