Make it easy to search for and include vendor gem paths in Sprockets
Go to file
John Bintz f81e0900d4 make it stupid-simple to use 2012-08-02 12:50:20 -04:00
lib make it stupid-simple to use 2012-08-02 12:50:20 -04:00
spec Use backwards compatible rubygems api 2012-07-31 10:00:42 -07:00
.gitignore initial commit 2012-02-06 13:51:21 -05:00
Gemfile initial commit 2012-02-06 13:51:21 -05:00
LICENSE initial commit 2012-02-06 13:51:21 -05:00
README.md make it stupid-simple to use 2012-08-02 12:50:20 -04:00
Rakefile initial commit 2012-02-06 13:51:21 -05:00
sprockets-vendor_gems.gemspec make it stupid-simple to use 2012-08-02 12:50:20 -04:00

README.md

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:

# 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

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::Environment.new('.')
Sprockets.find_gem_vendor_paths(:for => :javascript).each do |path|
  env.append_path path
end

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

Yeah!

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.