コード例 #1
0
def spriteImagesFromCss(x):
    
    css = x['css']
    
    d = {}
    for m in re.finditer(CSS_SPRITE_REGEX, css):
        
        spriteName = m.group('spriteName')
        backgroundUrl = m.group('backgroundUrl')
        imageUrl = expandUrl(backgroundUrl, os.path.expanduser(x['root']))
        
        if spriteName not in d:
            d[spriteName] = []
        d[spriteName].append(imageUrl)
    
    return {
        'sprite_images_map': d,
    }
コード例 #2
0
 def f(m):
     
     spriteUrl = x['sprite_urls'][m.group('spriteName')]
     backgroundUrl = m.group('backgroundUrl')
     imageUrl = expandUrl(backgroundUrl, os.path.expanduser(x['root']))
     ix, iy, iw, ih = x['layout'][imageUrl]
     
     css = 'background: url("%s") %s %s;\n' % (
                 spriteUrl,
                 '0' if ix == 0 else str(-ix) + 'px',
                 '0' if iy == 0 else str(-iy) + 'px')
     
     #TODO: match indent
     w, h = m.group('width'), m.group('height')
     if w and h:
         w, h = int(w), int(h)
         assert (w, h) == (iw, ih), [[w, h], [iw, ih]]
         css += 'width: %dpx;\nheight: %dpx;\n' % (w, h)
     
     return css