Get at available assets in loaded gems in Sprockets
Who says you need Rails Engines to use the vendored assets in gems? All you need is
The easiest way? Punch Sprockets right in the duck!
So, for instance, in Sinatra with sinatra-sprockets:
# config.ru require 'sinatra/base' require 'sprockets-vendor_gems/extend_all' require 'sinatra/sprockets' class MyApp < Sinatra::Base register Sinatra::Sprockets get '/' do "hi" end end map "/assets" do run Sinatra::Sprockets.environment end run MyApp
Sprockets::Environment instance now has every vendored gems asset path added!
By default, that's the
images directories. Need more?
Sprockets::VendorGems.default_types << "coolthings"
Do that before any
Sprockets::Environments get instantiated.
Want more manual control? Either get the list of asset paths:
or, instead of duck punching all of Sprockets, get an Environment with those paths in there already:
require 'sprockets-vendor_gems' env = Sprockets::EnvironmentWithVendoredGems.new
You may have to futz a bit with
require and fake classes for particular gems, especially if they really
rely on Rails to get their job done.