zweilove / css_splitter

Gem for splitting up stylesheets that go beyond the IE limit of 4095 selectors, for Rails 3.1+ apps using the Asset Pipeline.
MIT License
160 stars 47 forks source link

split2 file is always empty #34

Closed marc-villanueva closed 10 years ago

marc-villanueva commented 10 years ago

We recently updated our application from the 0.2.0 release of the gem to the current master. Now our application_split2.css file is always empty even though it is well past the 4095 selector count. After a bit of debugging, this clause in splitter.rb:42 always evaluates to true for every rule in the file. Therefore, nothing is ever written to the split file.

if rule =~ /^\s*}$/
  current_media = nil
  # skip the line if the close bracket is the first rule for the new file
  next if first_hit
end

I wrote a simple test to verify:

def test_split_string_failure
    second_part = CssSplitter::Splitter.split_string(File.read('test/dummy/app/assets/stylesheets/test_stylesheet_with_media_queries.css'), 2)
  refute_empty second_part
end

Is anyone else seeing this issue?

jhilden commented 10 years ago

@marc-villanueva can you test again with the current version from master? I think #35 should have fixed your issue.

aaronjensen commented 10 years ago

I just tried master on our project and had the same problem.

jhilden commented 10 years ago

Thanks for the feedback @aaronjensen Could you provide additional details about your setup/files? Did you follow the new instructions in the README (e.g. use require instead of include)? How is your original stylesheet composed?

aaronjensen commented 10 years ago

Yep, I used require and dropped the .split2 suffix. I'm not sure what you mean by composure, but it uses @import statements. The current gem release works fine.

aaronjensen commented 10 years ago

I also nuked public/assets and tmp/cache/assets

jhilden commented 10 years ago

Yes, with composure I was referring to Sass @import vs. sprockets etc.

I just did a test run with this file (https://github.com/zweilove/css_splitter/blob/master/test/dummy/app/assets/stylesheets/combined.css.scss) using @import instead of require and it worked well.

Any more details you can provide?

aaronjensen commented 10 years ago

hmm, not sure. Rails 4.0.4, sass 3.2.19, sprockets 2.11.0. I'm also using sprockets-derailleur.

jhilden commented 10 years ago

I lack the intimate knowledge of how sprockets works, but I would think it might be worth trying it without sprockets-derailleur

aaronjensen commented 10 years ago

@jhilden same result w/o it. I see the same behavior that @marc-villanueva sees, splitter.rb:42 is always true. Every rule ends in a curly brace, so i'm not entirely sure what that line of code is meant to do.