add lib/ and app/ to vendored assets search, fixes #93

This commit is contained in:
John Bintz 2011-12-08 09:13:45 -05:00
parent 84e369d30a
commit 7dde9328df
2 changed files with 46 additions and 15 deletions

View File

@ -10,26 +10,34 @@ module Jasmine::Headless
include FileChecker
class << self
def vendor_asset_paths
return @vendor_asset_paths if @vendor_asset_paths
def asset_paths
return @asset_paths if @asset_paths
require 'rubygems'
raise StandardError.new("A newer version of Rubygems is required to use vendored assets. Please upgrade.") if !Gem::Specification.respond_to?(:each)
@vendor_asset_paths = []
@asset_paths = []
Gem::Specification.each do |spec|
path = File.join(spec.gem_dir, 'vendor/assets/javascripts')
Gem::Specification.each { |gemspec| @asset_paths += get_paths_from_gemspec(gemspec) }
@vendor_asset_paths << path if File.directory?(path) && !@vendor_asset_paths.include?(path)
@asset_paths
end
@vendor_asset_paths
def get_paths_from_gemspec(gemspec)
%w{vendor lib app}.collect do |dir|
path = File.join(gemspec.gem_dir, dir, "assets/javascripts")
if File.directory?(path) && !@asset_paths.include?(path)
path
else
nil
end
end.compact
end
def reset!
@vendor_asset_paths = nil
@asset_paths = nil
# register haml-sprockets if it's available...
%w{haml-sprockets}.each do |library|
@ -104,7 +112,7 @@ module Jasmine::Headless
return @search_paths if @search_paths
@search_paths = [ Jasmine::Core.path, Jasmine::Headless.root.join('vendor/assets/javascripts').to_s ]
@search_paths += self.class.vendor_asset_paths
@search_paths += self.class.asset_paths
@search_paths += src_dir.collect { |dir| File.expand_path(dir) }
@search_paths += asset_paths.collect { |dir| File.expand_path(dir) }
@search_paths += spec_dir.collect { |dir| File.expand_path(dir) }

View File

@ -49,6 +49,29 @@ describe Jasmine::Headless::FilesList do
end
end
describe '.get_paths_from_gemspec' do
include FakeFS::SpecHelpers
let(:gem_dir) { "dir" }
let(:gemspec) { stub(:gem_dir => gem_dir) }
let(:paths) do
%w{vendor lib app}.collect do |dir|
File.join(gem_dir, dir, 'assets/javascripts')
end
end
before do
paths.each { |path| FileUtils.mkdir_p path }
described_class.instance_variable_set(:@asset_paths, [])
end
subject { described_class.get_paths_from_gemspec(gemspec) }
it { should =~ paths }
end
describe '#search_paths' do
no_default_files!
@ -66,7 +89,7 @@ describe Jasmine::Headless::FilesList do
let(:path) { 'path' }
before do
Jasmine::Headless::FilesList.stubs(:vendor_asset_paths).returns([])
Jasmine::Headless::FilesList.stubs(:asset_paths).returns([])
end
let(:vendor_path) { Jasmine::Headless.root.join('vendor/assets/javascripts').to_s }
@ -79,7 +102,7 @@ describe Jasmine::Headless::FilesList do
context 'vendored gem paths' do
before do
Jasmine::Headless::FilesList.stubs(:vendor_asset_paths).returns([ path ])
Jasmine::Headless::FilesList.stubs(:asset_paths).returns([ path ])
end
it 'should add the vendor gem paths to the list' do
@ -110,7 +133,7 @@ describe Jasmine::Headless::FilesList do
end
end
describe '.vendor_asset_paths' do
describe '.asset_paths' do
include FakeFS::SpecHelpers
let(:dir_one) { 'dir_one' }
@ -120,7 +143,7 @@ describe Jasmine::Headless::FilesList do
let(:gem_two) { stub(:gem_dir => dir_two) }
before do
described_class.instance_variable_set(:@vendor_asset_paths, nil)
described_class.instance_variable_set(:@asset_paths, nil)
FileUtils.mkdir_p File.join(dir_two, 'vendor/assets/javascripts')
@ -128,7 +151,7 @@ describe Jasmine::Headless::FilesList do
end
it 'should return all matching gems with vendor/assets/javascripts directories' do
described_class.vendor_asset_paths.should == [ File.join(dir_two, 'vendor/assets/javascripts') ]
described_class.asset_paths.should == [ File.join(dir_two, 'vendor/assets/javascripts') ]
end
end