diff --git a/docs/changelog.rst b/docs/changelog.rst index d7fc4ce..808bde5 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -5,3 +5,5 @@ Changelog ^^^^^ * New command line argument ``-z``, ``--no-size`` to avoid adding the image width and height to the sprite. * New command line argument ``--png8`` forces the output image format to be png8 instead of png32. +* Improve CSS parsing performance removing bloat in the CSS. +* Improved documentation. diff --git a/glue.py b/glue.py index 6ce6808..5792328 100755 --- a/glue.py +++ b/glue.py @@ -466,23 +466,30 @@ def save_css(self): css_file = open(css_filename, 'w') + # get all the class names and join them + class_names = ['.%s' % i.class_name for i in self.images] + class_names = ',\n'.join(class_names) + + # create an unique style for all the sprites for less bloat + style = "%s{background-image:url('%s');background-repeat:no-repeat;}\n" + css_file.write(style % (class_names, self.image_url)) + for image in self.images: - data = {'namespace': image.sprite.namespace, - 'sprite_url': image.sprite.image_url, - 'image_class_name': image.class_name, + data = {'image_class_name': image.class_name, 'top': image.node.y * -1 if image.node.y else 0, 'left': image.node.x * -1 if image.node.x else 0, 'width': image.width, 'height': image.height} - style = (".%(image_class_name)s{ " - "background:url('%(sprite_url)s') no-repeat " - "%(left)ipx %(top)ipx; ") + style = (".%(image_class_name)s{" + "background-position:%(left)ipx %(top)ipx;") if self.config.size: + # if it's required add the image size to the sprite style += "width:%(width)spx; height:%(height)spx;" style += "}\n" + css_file.write(style % data) css_file.close()