From 09c2936009c8d9342879cc1634043e7127ce492b Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 6 Feb 2012 13:51:21 -0500 Subject: [PATCH] initial commit --- .gitignore | 17 +++++++++++++++++ Gemfile | 4 ++++ LICENSE | 22 +++++++++++++++++++++ README.md | 36 +++++++++++++++++++++++++++++++++++ Rakefile | 2 ++ lib/sprockets-vendor_gems.rb | 30 +++++++++++++++++++++++++++++ sprockets-vendor_gems.gemspec | 16 ++++++++++++++++ 7 files changed, 127 insertions(+) create mode 100644 .gitignore create mode 100644 Gemfile create mode 100644 LICENSE create mode 100644 README.md create mode 100644 Rakefile create mode 100644 lib/sprockets-vendor_gems.rb create mode 100644 sprockets-vendor_gems.gemspec diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d87d4be --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +*.gem +*.rbc +.bundle +.config +.yardoc +Gemfile.lock +InstalledFiles +_yardoc +coverage +doc/ +lib/bundler/man +pkg +rdoc +spec/reports +test/tmp +test/version_tmp +tmp diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..60b82d6 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +# Specify your gem's dependencies in sprockets-vendor_gems.gemspec +gemspec diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..87b491e --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +Copyright (c) 2012 John Bintz + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e6a2096 --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +# Get at available assets in loaded gems in Sprockets + +Either get the list of asset paths: + +``` ruby +require 'sprockets-vendor_gems' + +env = Sprockets::Environment.new('.') +Sprockets.find_gem_vendor_paths(:for => :javascript).each do |path| + env.append_path path +end +``` + +or get an Environment with those paths in there already: +``` ruby +require 'sprockets-vendor_gems' + +env = Sprockets::EnvironmentWithVendoredGems.new('.') +``` + +Yeah! + +## Installation + +Add this line to your application's Gemfile: + + gem 'sprockets-vendor_gems' + +And then execute: + + $ bundle + +Or install it yourself as: + + $ gem install sprockets-vendor_gems + diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..f57ae68 --- /dev/null +++ b/Rakefile @@ -0,0 +1,2 @@ +#!/usr/bin/env rake +require "bundler/gem_tasks" diff --git a/lib/sprockets-vendor_gems.rb b/lib/sprockets-vendor_gems.rb new file mode 100644 index 0000000..c406619 --- /dev/null +++ b/lib/sprockets-vendor_gems.rb @@ -0,0 +1,30 @@ +require "sprockets" + +module ::Sprockets + class << self + def find_gem_vendor_paths(options = {}) + for_types = [ options[:for] || [ 'javascripts', 'stylesheets' ] ].flatten + + paths = [] + + Gem::Specification.each do |gemspec| + %w{vendor lib app}.product(for_types).each do |base_dir, type| + path = File.join(gemspec.gem_dir, base_dir, "assets", type.to_s) + + paths << path if File.directory?(path) + end + end + + paths + end + end + + class EnvironmentWithVendoredGems < Environment + def initialize(*args) + super(*args) + + Sprockets.find_gem_vendor_paths.each { |path| append_path(path) } + end + end +end + diff --git a/sprockets-vendor_gems.gemspec b/sprockets-vendor_gems.gemspec new file mode 100644 index 0000000..0f7bb9b --- /dev/null +++ b/sprockets-vendor_gems.gemspec @@ -0,0 +1,16 @@ +# -*- encoding: utf-8 -*- +Gem::Specification.new do |gem| + gem.authors = ["John Bintz"] + gem.email = ["john@coswellproductions.com"] + gem.description = %q{Get the vendored assets paths in gems.} + gem.summary = %q{Get the vendored assets paths in gems.} + gem.homepage = "" + + gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } + gem.files = `git ls-files`.split("\n") + gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") + gem.name = "sprockets-vendor_gems" + gem.require_paths = ["lib"] + gem.version = '1.0.0' +end +