documentcloud / jammit

Industrial Strength Asset Packaging for Rails
http://documentcloud.github.com/jammit/
MIT License
1.16k stars 197 forks source link

Adding Jammit::Packager#includes? to detect existence of compiled assets. #246

Open andrewhao opened 11 years ago

andrewhao commented 11 years ago

This allows us to detect the existence of a packaged asset at runtime, and gives us the ability to determine whether to call the Jammit stylesheet/javascript helper or the default Rails tag helpers.

jashkenas commented 11 years ago

Tell us a bit about your use case, please.

andrewhao commented 11 years ago

@jashkenas: I'm stuck in a Rails 2 app which on a per-controller basis loads in a custom stylesheet/script tag. Say I need to load "admin.js".

Now in a content_for block in my view, I had simply been rendering javascript_include_tag :admin. I'd like to basically render include_javascripts :admin and use the Jammit package if it exists, and otherwise fall back to javascript_include_tag if it doesn't.

jashkenas commented 11 years ago

Sounds pretty special case. Can't you just define these custom asset packages, and use them? Too many? Even to do in a loop in ERB in your assets.yml?

andrewhao commented 11 years ago

@jashkenas Yep, those are all valid alternatives. I just thought it'd be nice to add an extra layer of abstraction so I didn't have to know about Jammit configuration implementation.

What are your concerns? I could perhaps extract this method into a new Jammit::Configuration object if you're concerned about model bloat.