more sprockets improvements

This commit is contained in:
John Bintz 2011-11-20 11:56:25 -05:00
parent 61c8ed8828
commit ca8c655f00
4 changed files with 30 additions and 5 deletions

View File

@ -1,6 +1,7 @@
require 'jasmine-core'
require 'time'
require 'multi_json'
require 'set'
module Jasmine::Headless
class FilesList
@ -35,6 +36,7 @@ module Jasmine::Headless
@files = []
@filtered_files = []
@checked_dependency = Set.new
DEFAULT_FILES.each { |file| add_dependency('require', file, nil) }
@ -96,7 +98,12 @@ module Jasmine::Headless
end
def add_dependencies(file, source_root)
TestFile.new(file, source_root).dependencies.each { |type, name| add_dependency(type, name, source_root) }
TestFile.new(file, source_root).dependencies.each do |type, name|
if !@checked_dependency.include?(name)
@checked_dependency << name
add_dependency(type, name, source_root)
end
end
end
EXTENSION_FILTER = %r{(#{(%w{.js .css} + Sprockets.engine_extensions).join('|')})$}
@ -124,7 +131,11 @@ module Jasmine::Headless
ok = (root == file)
ok ||= File.basename(path.gsub("#{file}.", '')).split('.').all? { |part| ".#{part}"[EXTENSION_FILTER] }
return [ File.expand_path(path), File.expand_path(dir) ] if ok
expanded_path = File.expand_path(path)
if ok
return [ expanded_path, File.expand_path(dir) ]
end
end
end

View File

@ -24,6 +24,8 @@ module Jasmine::Headless
@dependencies = processor.directives.collect do |_, type, name|
if name[%r{^\.}]
name = File.expand_path(File.join(File.dirname(path), name)).gsub(%r{^#{source_root}/}, '')
else
raise Sprockets::ArgumentError.new("require_tree needs a relative path: ./#{path}") if type == 'require_tree'
end
[ type, name ]

View File

@ -1,5 +1,5 @@
//= require 'jquery'
//= require_tree 'things/templates'
//= require_tree './templates'
//= require 'things/required'
window.a = '1';

View File

@ -82,9 +82,11 @@ describe Jasmine::Headless::TestFile do
describe '#dependencies' do
include FakeFS::SpecHelpers
let(:directive) { 'require' }
before do
FileUtils.mkdir_p File.dirname(path)
File.open(path, 'wb') { |fh| fh.print "//= require '#{req}'\njavascript" }
File.open(path, 'wb') { |fh| fh.print "//= #{directive} '#{req}'\njavascript" }
end
context 'absolute' do
@ -92,7 +94,17 @@ describe Jasmine::Headless::TestFile do
subject { file.dependencies }
it { should == [ [ 'require', req ] ] }
context 'require' do
it { should == [ [ 'require', req ] ] }
end
context 'require_tree' do
let(:directive) { 'require_tree' }
it 'should raise an error' do
expect { subject }.to raise_error(Sprockets::ArgumentError, /relative/)
end
end
end
context 'relative' do