Stripping spaces that are necessary
I've got a bug report in a my project against cssmin: https://github.com/middleman/middleman/issues/254
Basically:
@media handheld, only screen and (device-width: 768px), (device-width: 800px)
will strip the space between and and ( and get turned into this invalid css:
@media handheld, only screen and(device-width: 768px), (device-width: 800px)
i have also came across this problem :-(
I was interested in tackling this bug, but then saw that there aren't any tests. We should totally write some of those! :)
Totally! I don't use cssmin myself anymore so I haven't touched it in a while, but pull requests are more than welcome.
What do you use these days, out of interest? We considered switching to another minification engine in AssetHat to get around this.
consider https://github.com/sprsquish/rainpress
Rainpress removes a different space (lol):
@media handheld,only screen and (device-width:768px)
I use YUI Compressor these days. The compression routines in cssmin.rb are based on an early compressor called cssmin.js that was written by Isaac Schlueter, and which also later became the basis for the CSS compression routines in YUI Compressor, so they're very similar. The main difference is that YUI Compressor is more actively maintained and treats media queries correctly, although since it's not Ruby it's obviously harder to integrate into Ruby projects.
In any case, I'd be happy to accept pull requests with fixes or tests, and I'll probably get around to fixing this myself eventually if no one else contributes a patch, but it's not high on my todo list since I don't personally need it.
WRT this problem, it looks like YUI just adds the space back in after stripping: https://github.com/yui/yuicompressor/blob/master/src/com/yahoo/platform/yui/compressor/CssCompressor.java#L234-236
@rgrove if i were to write a test for this case, is there a framework you'd prefer over rspec?
@dwo MiniTest is probably what I'd go with these days. Thanks for asking!
my own trial css_press. Pure ruby, real css parser