Last active
August 29, 2015 14:04
-
-
Save wtnabe/13022d05a10286b319af to your computer and use it in GitHub Desktop.
Sinatra + Sinatra::Sprockets + rails-asset.org + append paths
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'find' | |
map "/#{Sinatra::Sprockets.config.prefix}" do | |
env = Sinatra::Sprockets.environment | |
installed_assets = Bundler.definition.resolve.select {|e| | |
e.name =~ /^rails-assets/ | |
}.map {|e| | |
spec = e.instance_variable_get(:@specification) | |
[spec.name, spec.version].join('-') | |
} | |
if installed_assets.size > 0 | |
bundle_root = File.join( | |
Bundler.root, | |
Bundler.settings.instance_variable_get(:@local_config)['BUNDLE_PATH'], | |
Bundler.ruby_scope, | |
'gems' | |
) | |
assets_parent_dir = "vendor/assets" | |
Find.find(bundle_root) {|path| | |
next unless File.directory?(path) | |
next unless installed_assets.include?(File.basename(path)) | |
%w(javascripts stylesheets images fonts).each {|asset| | |
assets_dir = File.join(path, assets_parent_dir, asset) | |
if File.directory?(assets_dir) and !env.paths.include?(assets_dir) | |
env.append_path assets_dir | |
Find.prune | |
end | |
} | |
} | |
end | |
env.append_path "assets/javascripts" | |
env.append_path "assets/stylesheets" | |
run env | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment