Created
April 11, 2010 21:44
-
-
Save k1000/363092 to your computer and use it in GitHub Desktop.
build CSS 4 IE
This file contains 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
# -*- coding: utf-8 -*- | |
import sys, re, time | |
#based on http://stackoverflow.com/questions/222581/python-script-for-minifying-css | |
#css = open( sys.argv[1] , 'r' ).read() | |
myfile = "style.css" | |
css = open( "style.css" , 'r' ).read() | |
css = re.sub( r'\s+', ' ', css ) | |
print "/* ---------------------------------------------------------------------*/" | |
print "/* -------------- GENERATED FROM %s AT %s ------------*/" % (myfile, time.strftime( "%d %b %Y %H:%M", time.gmtime()) ) | |
print "/* ----------------------------------------------------------------------*/\n\n" | |
print """ | |
""" | |
properties = {} | |
for rule in re.findall( r'([^{]+){([^}]*)}', css ): | |
selectors = [re.sub( r'(?<=[\[\(>+=])\s+|\s+(?=[=~^$*|>+\]\)])', r'', selector.strip() ) for selector in rule[0].split( ',' )] | |
properties = {} | |
porder = [] | |
for prop in re.findall( '(.*?):(.*?)(;|$)', rule[1] ): | |
key = prop[0].strip().lower() | |
if key not in porder: porder.append( key ) | |
properties[ key ] = prop[1].strip() | |
out = ["%s{" % rule[0].strip(),] | |
if ('opacity' in properties): | |
opacity_value= int(float(properties['opacity']) * 100) | |
out.append("filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=%s); /* IE7 fix */" % opacity_value) | |
out.append("-ms-filter: #progid:DXImageTransform.Microsoft.Alpha(Opacity=%s); /* IE8 fix */" % opacity_value) | |
#http://www.communitymx.com/content/article.cfm?page=2&cid=C37E0 | |
#if ('margin' in properties) or ('margin-left' in properties) or ('margin-right' in properties): | |
#if "position" not in properties: | |
#out.append("position: relative; /* fix margin in IE */") | |
#out.append("zoom: 1; /* triggers hasLayout */") | |
#out.append("height: 1%; /* IE/Win Unscrollable Content Bug */") | |
if "min-height" in properties: | |
out.append("height:auto !important; height: %s; /* fix min-height */" % properties["min-height"]) | |
if ("display" in properties): | |
out.append("zoom: 1; /* triggers hasLayout */") | |
if ("background" in properties): | |
url = re.match(r'url\((.*\.png)\)', properties["background"]) | |
norepeat = re.match(r'.*no-repeat', properties["background"]) | |
if url and norepeat: | |
out.append("filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='%s',sizingMethod='crop');" % url.group(1) ) | |
if len(out) is not 1: | |
out.append("}") | |
print "\n\t".join(out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment