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

Update gems (Middleman compatibility) #31

Closed bluerouse closed 10 years ago

bluerouse commented 10 years ago

I just found your gem, which would do exactly what i'm currently searching for. I've got now some issues: we rely on middleman in the Version 3.1.6 and this makes some dependency-problems with your gem:

Bundler could not find compatible versions for gem "rack":
In Gemfile:
css_splitter (~> 0.2.0) ruby depends on 
rack (~> 1.4.5) ruby
middleman-livereload (>= 0) ruby depends on 
rack (1.5.2)

Bundler could not find compatible versions for gem "activesupport":
In Gemfile:
css_splitter (~> 0.2.0) ruby depends on 
activesupport (= 3.1.0) ruby
middleman-livereload (>= 0) ruby depends on 
activesupport (3.2.16)

How can i solve this? Is there a way for me to use your gem without using older gems than now?

Thanks a lot for your help!

Umofomia commented 10 years ago

It looks like this is caused by the fact that this gem includes its own Gemfile.lock. Because of this, this forces any other dependent projects to also use the same versions.

In general, Gemfile.lock should never be included in gems (but should be included when developing apps). See http://yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/:

When developing a gem ... Do not check your Gemfile.lock into version control, since it enforces precision that does not exist in the gem command, which is used to install gems in practice. Even if the precision could be enforced, you wouldn’t want it, since it would prevent people from using your library with versions of its dependencies that are different from the ones you used to develop the gem.

jhilden commented 10 years ago

The Gemfile.lock should definitely not be in the repo, so I merge #32

However, I'm not sure this is causing the issue at hand here. The only runtime depency, as defined in the gemspec, should be rails >= 3.1.

@bluerouse can you still test with the current master if that should fix your issue after all?

The proper solution for middleman compatibility would probably be to depend on sprockets (I think >= 2.0.0) instead of rails. I would gladly take PR for that if somebody can confirm that it fixes middleman compatibility.

bluerouse commented 10 years ago

Errormessage remains the same. Seems like there is a bigger issue than just the gemfile.lock was.

jhilden commented 10 years ago

Just as I thought. Would you be able to create a new fork of the gem with the rails dependency replaced with sprockets (as described above) and let me know if that fixes things for you?

jhilden commented 10 years ago

this is the relevant line: https://github.com/zweilove/css_splitter/blob/master/css_splitter.gemspec#L20

bluerouse commented 10 years ago

Thanks for your help! I did this change and now "bundle install" is successful. But the gem throws an error now:

engine.rb:2:in `module:CssSplitter': uninitialized constant Rails (NameError)

jhilden commented 10 years ago

Ah, right. In that case we would need a different way to register the SprocketsEngine (https://github.com/zweilove/css_splitter/blob/master/lib/css_splitter/engine.rb). Unfortunately I don't really know how to do that :( Maybe sombody that knows middleman well could help?

bluerouse commented 10 years ago

Tried the following:

What did I miss to try? I'm not that familiar with Ruby, the errors are quite hard to understand.

Probably middleman-developers got an idea? @tdreyno @bhollis

Thanks for your help!

tdreyno commented 10 years ago

Looks like the base css_splitter lib file automatically sets up Rails support, which doesn't exist in Middleman:

require "css_splitter/engine"
require "css_splitter/sprockets_engine"
require "css_splitter/splitter"

module CssSplitter
end

I'd replace your require "css_splitter" with a truncated version of their includes:

require "css_splitter/sprockets_engine"
require "css_splitter/splitter"

module CssSplitter
end

Simply omitting the Rails engine, but keeping the Sprockets support. I'll let this gem's authors comment on whether that will actually work.

jhilden commented 10 years ago

This should already help by only loading the engine integration if Rails is actually defined 62039bcb8b1eac963df02f058f7e7ca987358408

However, you will somehow need to register the gem's SprocketsEngine as a bundle processor in Middleman, and I'm not sure how that would work (see: https://github.com/zweilove/css_splitter/blob/master/lib/css_splitter/engine.rb#L6)

Umofomia commented 10 years ago

Changing s.add_dependency "rails", ">= 3.1" line to use add_development_dependency instead in css_splitter.gemspec might also help. In addition, because the Rails dependency would no longer be required, I would add a dependency on sprockets instead.

bluerouse commented 10 years ago

Yes, now i could bundle my project with css_splitter and also start middleman! I didn't reached to register the precompile-thing. Probably middleman handles this already for me? I tried to register config.assets.precomile in my config.rb, but this didn't work.

But i even tried to open a page in project without this precompile-registering, then errormessage is like this: undefined method `split_stylesheet_link_tag' for #Middleman::Application:0x70215241268140

I think solution is very close, probably i made a small thing wrong?

Thanks for your support!

jhilden commented 10 years ago

You will need to find the correct way of registering the bundle processor and including the split_stylesheet_link_tag helper in Middleman, otherwise you might be able to bundle the gem, but it's functionality will not be registered in your app. I would love to help more, but I have no experience with Middleman.

tdreyno commented 10 years ago

@bluerouse We don't precompile on our side, but open a ticket in our repo and I'll help you re-implement (or copy/import) the split_stylesheet_link_tag helpers into the Middleman environment.

bluerouse commented 10 years ago

As the dependecy issues are fixed, I'm closing this ticket. Thanks a lot for your help!