Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
69 lines (46 sloc) 1.58 KB

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 sprockets-vendor_gems. Use those cool vendored JavaScript & CSS gems in anything!

The easiest way? Punch Sprockets right in the duck!

require 'sprockets-vendor_gems/extend_all'

So, for instance, in Sinatra with sinatra-sprockets:


require 'sinatra/base'
require 'sprockets-vendor_gems/extend_all'
require 'sinatra/sprockets'

class MyApp < Sinatra::Base
  register Sinatra::Sprockets

  get '/' do

map "/assets" do
  run Sinatra::Sprockets.environment

run MyApp

Every Sprockets::Environment instance now has every vendored gems asset path added! By default, that's the javascripts, stylesheets, and 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:

require 'sprockets-vendor_gems'

env ='.')
Sprockets.find_gem_vendor_paths(:for => :javascript).each do |path|
  env.append_path path

or, instead of duck punching all of Sprockets, get an Environment with those paths in there already:

require 'sprockets-vendor_gems'

env =


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.

Something went wrong with that request. Please try again.