2012-02-08 13:42:07 +00:00
|
|
|
require 'sprockets'
|
|
|
|
require 'rubygems'
|
2012-02-06 18:51:21 +00:00
|
|
|
|
|
|
|
module ::Sprockets
|
2012-07-03 00:45:04 +00:00
|
|
|
def self.find_gem_vendor_paths(options = {})
|
|
|
|
options = { :paths => %w{vendor lib app} }.merge(options)
|
2012-02-06 18:51:21 +00:00
|
|
|
|
2012-07-03 00:45:04 +00:00
|
|
|
for_types = [ options[:for] || [ 'javascripts', 'stylesheets' ] ].flatten
|
2012-02-06 18:51:21 +00:00
|
|
|
|
2012-07-03 00:45:04 +00:00
|
|
|
paths = []
|
2012-02-06 18:51:21 +00:00
|
|
|
|
2012-07-31 17:00:42 +00:00
|
|
|
GemEnvironment.each do |gemspec|
|
2012-07-03 00:45:04 +00:00
|
|
|
options[:paths].product(for_types).each do |base_dir, type|
|
|
|
|
path = File.join(gemspec.gem_dir, base_dir, "assets", type.to_s)
|
2012-02-06 18:51:21 +00:00
|
|
|
|
2012-07-03 00:45:04 +00:00
|
|
|
paths << path if File.directory?(path)
|
|
|
|
end
|
2012-02-06 18:51:21 +00:00
|
|
|
end
|
2012-07-03 00:45:04 +00:00
|
|
|
|
|
|
|
paths
|
2012-02-06 18:51:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
class EnvironmentWithVendoredGems < Environment
|
|
|
|
def initialize(*args)
|
|
|
|
super(*args)
|
|
|
|
|
|
|
|
Sprockets.find_gem_vendor_paths.each { |path| append_path(path) }
|
|
|
|
end
|
|
|
|
end
|
2012-07-31 17:00:42 +00:00
|
|
|
|
|
|
|
class GemEnvironment
|
|
|
|
extend Enumerable
|
|
|
|
|
|
|
|
def self.gemspecs
|
|
|
|
Gem.loaded_specs.map(&:last)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.each(&block)
|
|
|
|
return enum_for(:each) unless block_given?
|
|
|
|
|
|
|
|
gemspecs.each {|spec| yield spec }
|
|
|
|
end
|
|
|
|
end
|
2012-02-06 18:51:21 +00:00
|
|
|
end
|
|
|
|
|