summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaniel g. siegel2013-06-20 20:06:51 +0200
committerdaniel g. siegel2013-06-20 20:06:51 +0200
commitc258e6adb009b3e36b81960cfcbfb8f0d8bf0e52 (patch)
treec9ea82c05325f00b8a0591600f136c86b6ee4833
downloadcssmin.py-c258e6adb009b3e36b81960cfcbfb8f0d8bf0e52.tar.gz
cssmin.py-c258e6adb009b3e36b81960cfcbfb8f0d8bf0e52.tar.bz2
cssmin.py-c258e6adb009b3e36b81960cfcbfb8f0d8bf0e52.zip
initial commit
-rw-r--r--README18
-rw-r--r--cssmin.py31
2 files changed, 49 insertions, 0 deletions
diff --git a/README b/README
new file mode 100644
index 0000000..630d741
--- /dev/null
+++ b/README
@@ -0,0 +1,18 @@
+cssmin.py
+---------
+
+a simple css minifier
+
+based on simple css minifier by rafał jońca.
+http://blog.rafaljonca.org/2007/11/simple-css-minifier.html
+
+usage
+-----
+
+python cssmin.py style.css > style.min.css
+
+
+license
+-------
+
+the (original) code is available on double license: gpl and mit.
diff --git a/cssmin.py b/cssmin.py
new file mode 100644
index 0000000..4b396a7
--- /dev/null
+++ b/cssmin.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+#-*- coding:utf-8 -*-
+#
+# based on Simple CSS Minifier by Rafał Jońca.
+# http://blog.rafaljonca.org/2007/11/simple-css-minifier.html
+# The (original) code is available on double license: GPL and MIT.
+
+import re
+import sys
+
+RULES = [
+ (r'\/\*.*?\*\/', ''), # remove comments
+ (r"\n", ""), # remove all newlines
+ (r'[\t ]+', " "), # change spaces and tabs to one space
+ (r'\s?([;:{},+>])\s?', r"\1"), # remove unneeded space
+ (r';}', "}"), # remove final semicolon
+]
+
+def minimalize(css):
+ css = css.replace("\r\n", "\n")
+ for rule in RULES:
+ css = re.compile(rule[0], re.MULTILINE|re.UNICODE|re.DOTALL).sub(rule[1], css)
+ return css
+
+if len(sys.argv) > 1:
+ filename = sys.argv[1]
+else:
+ print "usage: cssmin.py [file]"
+ sys.exit(1)
+
+print minimalize(open(filename, 'r').read())