Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve CSS parsing performance removing bloat in the CSS
- Loading branch information
Jorge Bastida
committed
Jan 11, 2012
1 parent
0cbab90
commit 9d27c2f
Showing
2 changed files
with
15 additions
and
6 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -466,23 +466,30 @@ def save_css(self): | |
|
||
css_file = open(css_filename, 'w') | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
# get all the class names and join them | ||
class_names = ['.%s' % i.class_name for i in self.images] | ||
This comment has been minimized.
Sorry, something went wrong.
exupero
|
||
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() | ||
|
Would a
with open(css_filename, 'w') as css_file:
be preferable here? It would eliminate the need forcss_file.close()
on line 495.I'm not sure how you feel about indenting such a big chunk of the code.