def test_colours_true(self): items = [ # short hex '#000', '#fff', '#FFF', '#123', '#456', '#789', '#abc', '#def', '#ABC', '#DEF', # long hex '#000000', '#ffffff', '#FFFFFF', '#123456', '#789abc', '#defABC', '#DEF000', # rgb 'rgb(0,0,0)', ' rgb ( 0 , 0 , 0 ) ', 'rgb(255,255,255)', ' rgb ( 255 , 255 , 255 ) ', # rgba 'rgba(0,0,0,0)', 'rgba(0,0,0,0.1)', ' rgba ( 0 , 0 , 0 , 0 ) ', ' rgba ( 0 , 0 , 0 , 0.1 ) ', 'rgba(255,255,255,1)', 'rgba(255,255,255,1.0)', ' rgba ( 255 , 255 , 255 , 1 ) ', ' rgba ( 255 , 255 , 255 , 1.0 ) ', # hsl 'hsl(0,0%,0%)', ' hsl ( 0 , 0 % , 0 % ) ', 'hsl(255,120%,120%)', ' hsl ( 255 , 120 % , 120 % ) ', # hsla 'hsla(0,0%,0%,0)', 'hsla(0,0%,0%,0.1)', ' hsla ( 0 , 0 % , 0 % , 0 ) ', ' hsla ( 0 , 0 % , 0 % , 0.1 ) ', 'hsla(255,120%,120%,1)', 'hsla(255,120%,120%,1.0)', ' hsla ( 255 , 120 % , 120 % , 1 ) ', ' hsla ( 255 , 140 % , 140 % , 1.0 ) ', ] items.extend(PREDEFINED) for item in items: self.assertTrue(is_colour(item), '%s was not True' % item)
def test_colours_false(self): items = ['#ff', '#ffff', '#fffff', '#fffffff', 'rgb(0,0,0,0)', 'rgba(0,0,0)', 'hsl(0,0,0)', 'hsl(0,0%,0%,0)', 'hsla(0,0,0)', 'hsla(0,0%,0%)', ] for item in items: self.assertFalse(is_colour(item), '%s was not False' % item)
def detect_types(self): # uses the sass compiler to create fake CSS classes in order to # evaluate the expressions in each value (whether in the component or # overridden), detects those that are colours and puts the detected # value in the component src = ['$bootstrap-sass-asset-helper:false;'] for name, value in self.all_value_pairs(): src.append('$%s:%s;' % (name, value)) src.append('.%s{color:%s}' % (name, value)) #with open('last_compile.txt', 'w') as f: # f.write('\n'.join(src)) result = sass.compile(string='\n'.join(src)) for match in self.css_pieces.finditer(result): name = match.group(1) value = match.group(2).strip() if is_colour(value): self.colour_values[name] = value
def detect_types(self): # uses the sass compiler to create fake CSS classes in order to # evaluate the expressions in each value (whether in the component or # overridden), detects those that are colours and puts the detected # value in the component src = ['$bootstrap-sass-asset-helper:false;'] for name, value in self.all_value_pairs(): src.append('$%s:%s;' % (name, value)) src.append('.%s{color:%s}' % (name, value)) #with open('last_compile.txt', 'w') as f: # f.write('\n'.join(src)) result = sass.compile(string='\n'.join(src)) for match in self.css_pieces.finditer(result): name = match.group(1) value = match.group(2).strip() if is_colour(value): self.colour_values[name] = value