1. Jason R. Coombs
  2. cssutils-hg-merge

Commits

cthedot  committed a821f11

new pref option omitLeadingZero

  • Participants
  • Parent commits 490db0c
  • Branches default

Comments (0)

Files changed (4)

File CHANGELOG.txt

View file
  • Ignore whitespace
       Issues are currently still at Google Code though.
 
     - Issue #53 feature request: Added new Preference option ``cssutils.ser.prefs.indentClosingBrace``. Defines if closing brace of block is indented to match indentation of the block (default) oder match indentation of selector.
+
 	- Fixed Issue #54 (thanks to Simon Sapin): Short hand like `#f80` color value object have correct red, green and blue property values now. Also ``hsl()`` and ``hsla()`` colors report (almost) correct values (due to rounding problems).
+
 	- Fixed Issue #55 (thanks to Simon Sapin): `outline-color` property was missing from validation.
 
+    - Feature request: Added new Preference option ``cssutils.ser.prefs.omitLeadingZero``. Defines if values between -1 and 1 should omit the 0, like ``.5px``. Minified settings do this, else 0 is kept by default.
+
 
 0.9.8a2 110611
     - BUGFIX: Fixed Issue #59 which showed a rather strange problem with longer space separated lists of font-family values being so slow to actually stop parsing.

File src/cssutils/serialize.py

View file
  • Ignore whitespace
     keepEmptyRules = False
         defines if empty rules like e.g. ``a {}`` are kept in the resulting
         serialized sheet
-    keepLeadingZero = True
-        defines if values between -1 and 1 should omit the 0, like ``.5px``
     keepUnknownAtRules = True
         defines if unknown @rules like e.g. ``@three-dee {}`` are kept in the
         serialized sheet
         used as being normalized anyway)
     omitLastSemicolon = True
         If ``True`` omits ; after last property of CSSStyleDeclaration
+    omitLeadingZero = False
+        defines if values between -1 and 1 should omit the 0, like ``.5px``
     paranthesisSpacer = u' '
         string which is used before an opening paranthesis like in a
         ``css.CSSMediaRule`` or ``css.CSSStyleRule``
         self.keepAllProperties = True
         self.keepComments = True
         self.keepEmptyRules = False
-        self.keepLeadingZero = True
         self.keepUnknownAtRules = True
         self.keepUsedNamespaceRulesOnly = False
         self.lineNumbers = False
         self.lineSeparator = u'\n'
         self.listItemSpacer = u' '
         self.normalizedVarNames = True
+        self.omitLeadingZero = False
         self.omitLastSemicolon = True
         self.paranthesisSpacer = u' '
         self.propertyNameSpacer = u' '
         self.indent = u''
         self.keepComments = False
         self.keepEmptyRules = False
-        self.keepLeadingZero = False
         self.keepUnknownAtRules = False
         self.keepUsedNamespaceRulesOnly = True
         self.lineNumbers = False
         self.lineSeparator = u''
         self.listItemSpacer = u''
+        self.omitLeadingZero = True
         self.omitLastSemicolon = True
         self.paranthesisSpacer = u''
         self.propertyNameSpacer = u''
                 elif value.value == int(value.value):
                     # cut off after . which is zero anyway
                     val = unicode(int(value.value))
-                elif not self.prefs.keepLeadingZero and -1 < value.value < 1:
+                elif self.prefs.omitLeadingZero and -1 < value.value < 1:
                     v = unicode(value.value)
                     val = v
                     if value._sign == u'-':

File src/tests/test_serialize.py

View file
  • Ignore whitespace
         self.assertEqual(cssutils.ser.prefs.keepAllProperties, True)
         self.assertEqual(cssutils.ser.prefs.keepComments, True)
         self.assertEqual(cssutils.ser.prefs.keepEmptyRules, False)
-        self.assertEqual(cssutils.ser.prefs.keepLeadingZero, True)
         self.assertEqual(cssutils.ser.prefs.keepUnknownAtRules, True)
         self.assertEqual(cssutils.ser.prefs.keepUsedNamespaceRulesOnly, False)
         self.assertEqual(cssutils.ser.prefs.lineNumbers, False)
         self.assertEqual(cssutils.ser.prefs.lineSeparator, u'\n')
         self.assertEqual(cssutils.ser.prefs.listItemSpacer, u' ')
         self.assertEqual(cssutils.ser.prefs.omitLastSemicolon, True)
+        self.assertEqual(cssutils.ser.prefs.omitLeadingZero, False)
         self.assertEqual(cssutils.ser.prefs.paranthesisSpacer, u' ')
         self.assertEqual(cssutils.ser.prefs.propertyNameSpacer, u' ')
         self.assertEqual(cssutils.ser.prefs.selectorCombinatorSpacer, u' ')
         self.assertEqual(cssutils.ser.prefs.keepAllProperties, True)
         self.assertEqual(cssutils.ser.prefs.keepComments, False)
         self.assertEqual(cssutils.ser.prefs.keepEmptyRules, False)
-        self.assertEqual(cssutils.ser.prefs.keepLeadingZero, False)
         self.assertEqual(cssutils.ser.prefs.keepUnknownAtRules, False)
         self.assertEqual(cssutils.ser.prefs.keepUsedNamespaceRulesOnly, True)
         self.assertEqual(cssutils.ser.prefs.lineNumbers, False)
         self.assertEqual(cssutils.ser.prefs.lineSeparator, u'')
         self.assertEqual(cssutils.ser.prefs.listItemSpacer, u'')
         self.assertEqual(cssutils.ser.prefs.omitLastSemicolon, True)
+        self.assertEqual(cssutils.ser.prefs.omitLeadingZero, True)
         self.assertEqual(cssutils.ser.prefs.paranthesisSpacer, u'')
         self.assertEqual(cssutils.ser.prefs.propertyNameSpacer, u'')
         self.assertEqual(cssutils.ser.prefs.selectorCombinatorSpacer, u'')

File src/try.py

View file
  • Ignore whitespace
                 return [('TYPE', v, 0, 0) for v in valuelist]
 
 
-if 1:
-   
-    def hsl2rgb(h, s, l): 
-       
-        def hue2rgb(m1, m2, h): 
-           if h<0: h += 1 #PUT h+1 IN h
-           if h>1: h -= 1 #PUT h-1 IN h
-           if h*6<1: return m1+(m2-m1)*6*h
-           if h*2<1: return m2
-           if h*3<2: return m1+(m2-m1)*((2.0/3.0)-h)*6
-           return m1
-       
-        if l<=0.5: 
-            m2 = l*(s+1)
-        else: 
-            m2 = l+s-l*s
-           
-        m1 = l*2-m2
-        r = hue2rgb(m1, m2, h+(1.0/3.0))
-        g = hue2rgb(m1, m2, h)
-        b = hue2rgb(m1, m2, h-(1.0/3.0)) 
-        return r, g, b
-    
-    
-
-    #print '=', hsl2rgb(0.5, 1.0, 0.5)
-    cc = 'hsla(120, 100%, 50%, 1.0)'
-    print cc
-    c = cssutils.css.ColorValue(cc)
-    print 'rgb', c.red, c.green, c.blue
-        
-#    import colorsys
-#    raw = [0, 100, 50] 
-#    
-#    def frac(x, base):
-#        return (x) / float(base)
-#    
-#    print 'raw=', raw
-#    h, s, l = (frac(raw[0], 255), 
-#               frac(raw[1], 100), 
-#               frac(raw[2], 100))
-#    print 'hsl=', h, s, l
-#    r, g, b = colorsys.hls_to_rgb(h, l, s) # ORDER h l s !!!
-#    print 'rgb=', r, g, b
-#    rgba = [int(r*255), int(g*255), int(b*255)]
-#    print rgba
-    sys.exit(0)
 
 if 1:
     #cssutils.ser.prefs.indentClosingBrace = False
     css = '''
-    @media all {x {left: 0}}
-    
     a {
-    outline: red;
+        left: .0;
+        left: 0.0;
+        left: .5;
+        top: 0.6;
+        top: -.5;
+        top: +.5;
+        left: .5px;
+        top: 0.6px;
+        top: -.5px;
+        top: +.5px;
+        left: .5%;
+        top: 0.6%;
+        top: -.5%;
+        top: +.5%;
     }'''
     print cssutils.parseString(css).cssText
+    cssutils.ser.prefs.keepLeadingZero = False
+    print cssutils.parseString(css).cssText
     sys.exit(0)