documentcloud / jammit

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

Possibility to choose the packager class #64

Closed fxposter closed 14 years ago

fxposter commented 14 years ago

Now the user is able to create a custom packager class:

class TestPackager < Jammit::Packager
end

and point Jammit to use this class by adding a "packager_class" option to assets.yml:

packager_class: TestPackager
jashkenas commented 14 years ago

Without a reason to subclass Jammit::Packager, I think this is a wontfix. If there's a particular configuration option you'd like to add, we should talk about that.

fxposter commented 14 years ago

We use this to enable "dynamic packaging". Sometimes we have a javascripts that we need to use only on one page and we really don't want to check, if it breaks something on other pages.

class MyPackager < Jammit::Packager
  def not_found(package, extension)
    dynamic_package_for(package, extension) || super
  end

  def dynamic_package_for(package, extension)
    dir = extension == :js ? "javascripts" : "stylesheets"
    url = "#{package}.#{extension}"
    path = "public/#{dir}/#{url}"
    { :paths => [path], :urls => [url] }
  end
end