diff --git a/Gemfile b/Gemfile
index 1679aed..4896aec 100644
--- a/Gemfile
+++ b/Gemfile
@@ -16,4 +16,4 @@ gem 'guard-jasmine-headless-webkit', :git => 'git://github.com/johnbintz/guard-j
gem 'facter'
gem 'jquery-rails'
-
+gem 'ejs'
diff --git a/jasmine-headless-webkit.gemspec b/jasmine-headless-webkit.gemspec
index 627b159..e7be2ec 100644
--- a/jasmine-headless-webkit.gemspec
+++ b/jasmine-headless-webkit.gemspec
@@ -24,5 +24,5 @@ Gem::Specification.new do |s|
s.add_dependency 'coffee-script', '>= 2.2'
s.add_dependency 'rainbow'
s.add_dependency 'multi_json'
- s.add_dependency 'sprockets', '~> 2.0'
+ s.add_dependency 'sprockets', '>= 2.0'
end
diff --git a/lib/jasmine/headless.rb b/lib/jasmine/headless.rb
index 664ccc0..58c11af 100644
--- a/lib/jasmine/headless.rb
+++ b/lib/jasmine/headless.rb
@@ -1,4 +1,5 @@
require 'pathname'
+require 'sprockets/engines'
module Jasmine::Headless
autoload :CoffeeScriptCache, 'jasmine/headless/coffee_script_cache'
@@ -24,3 +25,4 @@ module Jasmine::Headless
end
require 'jasmine/headless/errors'
+Sprockets::Engines
diff --git a/lib/jasmine/headless/files_list.rb b/lib/jasmine/headless/files_list.rb
index 86199fc..e577fef 100644
--- a/lib/jasmine/headless/files_list.rb
+++ b/lib/jasmine/headless/files_list.rb
@@ -57,7 +57,7 @@ module Jasmine::Headless
end
def search_paths
- @search_paths ||= [ Jasmine::Core.path, src_dir, spec_dir ] + self.class.vendor_asset_paths
+ @search_paths ||= [ Jasmine::Core.path, File.expand_path(src_dir), File.expand_path(spec_dir) ] + self.class.vendor_asset_paths
end
def has_spec_outside_scope?
@@ -92,6 +92,8 @@ module Jasmine::Headless
TestFile.new(file, source_root).dependencies.each { |type, name| add_dependency(type, name, source_root) }
end
+ EXTENSION_FILTER = %r{\.(js|css|coffee|jst.*)$}
+
def add_dependency(type, file, source_root)
case type
when 'require'
@@ -99,7 +101,7 @@ module Jasmine::Headless
add_file(*result)
end
when 'require_tree'
- Dir[File.join(source_root, file, '**/*.{js,css,coffee}')].each do |tree_path|
+ Dir[File.join(source_root, file, '**/*')].find_all { |path| File.file?(path) && path[EXTENSION_FILTER] }.sort.each do |tree_path|
if result = find_dependency(tree_path.gsub(%r{^#{source_root}/}, ''))
add_file(*result)
end
@@ -109,7 +111,7 @@ module Jasmine::Headless
def find_dependency(file)
search_paths.each do |dir|
- if file[%r{\.(js|css|coffee)$}]
+ if file[EXTENSION_FILTER]
if File.file?(path = File.join(dir, file))
return [ File.expand_path(path), File.expand_path(dir) ]
end
@@ -133,7 +135,11 @@ module Jasmine::Headless
alert_time = nil
end
- Jasmine::Headless::TestFile.new(file).to_html
+ search_paths.collect do |path|
+ if file[path]
+ Jasmine::Headless::TestFile.new(file, path).to_html
+ end
+ end.compact.first
}.flatten.compact.reject(&:empty?)
end
@@ -194,7 +200,7 @@ module Jasmine::Headless
end
def expanded_dir(path)
- Dir[path].collect { |file| File.expand_path(file) }
+ Dir[path].collect { |file| File.expand_path(file) }.find_all { |path| File.file?(path) && path[EXTENSION_FILTER] }
end
def add_file(file, source_root)
diff --git a/lib/jasmine/headless/test_file.rb b/lib/jasmine/headless/test_file.rb
index 7d8ee10..52167f8 100644
--- a/lib/jasmine/headless/test_file.rb
+++ b/lib/jasmine/headless/test_file.rb
@@ -1,5 +1,12 @@
require 'rainbow'
-require 'sprockets/directive_processor'
+require 'sprockets'
+
+%w{haml-sprockets}.each do |library|
+ begin
+ require library
+ rescue LoadError
+ end
+end
module Jasmine::Headless
class TestFile
@@ -38,6 +45,13 @@ module Jasmine::Headless
%{}
when '.css'
%{}
+ when '.jst'
+ to_jst(read)
+ else
+ case path
+ when %r{\.jst(\..*)$}
+ to_jst(Sprockets.engines($1).new { read }.evaluate(self, {}))
+ end
end
end
@@ -53,6 +67,19 @@ module Jasmine::Headless
[ type, name ]
end
end
+
+ def logical_path
+ path.gsub(%r{^#{source_root}/}, '').gsub(%r{\..+$}, '')
+ end
+
+ private
+ def to_jst(data)
+ %{}
+ end
+
+ def read
+ File.read(path)
+ end
end
end
diff --git a/spec/bin/jasmine-headless-webkit_spec.rb b/spec/bin/jasmine-headless-webkit_spec.rb
index e8fcbf9..cd665d7 100644
--- a/spec/bin/jasmine-headless-webkit_spec.rb
+++ b/spec/bin/jasmine-headless-webkit_spec.rb
@@ -146,6 +146,8 @@ describe "jasmine-headless-webkit" do
files.lines.to_a.should contain_in_order_in_file_list(
'vendor/assets/javascripts/jquery.js',
+ 'templates/that.jst.ejs',
+ 'templates/this.jst',
'assets/things/required.js',
'assets/things/code.js',
'assets/things/subcode/more_code.js',
diff --git a/spec/jasmine/with_sprockets_includes/assets/things/code.js b/spec/jasmine/with_sprockets_includes/assets/things/code.js
index bb2e8ae..89bab5e 100644
--- a/spec/jasmine/with_sprockets_includes/assets/things/code.js
+++ b/spec/jasmine/with_sprockets_includes/assets/things/code.js
@@ -1,3 +1,5 @@
+//= require 'jquery'
+//= require_tree 'things/templates'
//= require 'things/required'
window.a = '1';
diff --git a/spec/jasmine/with_sprockets_includes/assets/things/templates/that.jst.ejs b/spec/jasmine/with_sprockets_includes/assets/things/templates/that.jst.ejs
new file mode 100644
index 0000000..e69de29
diff --git a/spec/jasmine/with_sprockets_includes/assets/things/templates/this.jst b/spec/jasmine/with_sprockets_includes/assets/things/templates/this.jst
new file mode 100644
index 0000000..e69de29
diff --git a/spec/jasmine/with_sprockets_includes/spec/spec_helper.js b/spec/jasmine/with_sprockets_includes/spec/spec_helper.js
index 18241c9..4817b36 100644
--- a/spec/jasmine/with_sprockets_includes/spec/spec_helper.js
+++ b/spec/jasmine/with_sprockets_includes/spec/spec_helper.js
@@ -1,2 +1 @@
//= require 'jquery'
-
diff --git a/spec/jasmine/with_sprockets_includes/with_sprockets_includes.yml b/spec/jasmine/with_sprockets_includes/with_sprockets_includes.yml
index f5943f8..99cd320 100644
--- a/spec/jasmine/with_sprockets_includes/with_sprockets_includes.yml
+++ b/spec/jasmine/with_sprockets_includes/with_sprockets_includes.yml
@@ -5,7 +5,7 @@ spec_files:
- "**/*_spec.js"
src_files:
- - "things/**/*.js"
+ - "things/**/*"
helpers:
- "spec_helper.js"
diff --git a/spec/lib/jasmine/headless/files_list_spec.rb b/spec/lib/jasmine/headless/files_list_spec.rb
index 4cb0742..82f36a8 100644
--- a/spec/lib/jasmine/headless/files_list_spec.rb
+++ b/spec/lib/jasmine/headless/files_list_spec.rb
@@ -161,46 +161,6 @@ describe Jasmine::Headless::FilesList do
end
end
- describe '#.*files_to_html' do
- include FakeFS::SpecHelpers
-
- before do
- files_list.instance_variable_set(:@files, [
- 'test.js',
- 'test.coffee',
- 'test.whatever',
- 'test.css'
- ])
-
- files_list.instance_variable_set(:@filtered_files, [
- 'test.js',
- 'test.coffee'
- ])
-
- File.stubs(:read)
- Jasmine::Headless::CoffeeScriptCache.any_instance.stubs(:handle).returns("i compiled")
- end
-
- context '#files_to_html' do
- it "should create the right HTML" do
- files_list.files_to_html.should == [
- %{},
- %{},
- %{}
- ]
- end
- end
-
- context '#filtered_files_to_html' do
- it "should create the right HTML" do
- files_list.filtered_files_to_html.should == [
- %{},
- %{}
- ]
- end
- end
- end
-
describe '#spec_file_line_numbers' do
include FakeFS::SpecHelpers
@@ -292,7 +252,7 @@ describe Jasmine::Headless::FilesList do
end
it 'should take the src dir and spec dirs' do
- files_list.search_paths.should == [ Jasmine::Core.path, src_dir, spec_dir ]
+ files_list.search_paths.should == [ Jasmine::Core.path, File.expand_path(src_dir), File.expand_path(spec_dir) ]
end
end
@@ -302,7 +262,7 @@ describe Jasmine::Headless::FilesList do
end
it 'should add the vendor gem paths to the list' do
- files_list.search_paths.should == [ Jasmine::Core.path, src_dir, spec_dir, path ]
+ files_list.search_paths.should == [ Jasmine::Core.path, File.expand_path(src_dir), File.expand_path(spec_dir), path ]
end
end
end
diff --git a/spec/lib/jasmine/headless/test_file_spec.rb b/spec/lib/jasmine/headless/test_file_spec.rb
index 0265286..14f053b 100644
--- a/spec/lib/jasmine/headless/test_file_spec.rb
+++ b/spec/lib/jasmine/headless/test_file_spec.rb
@@ -72,6 +72,38 @@ describe Jasmine::Headless::TestFile do
end
end
end
+
+ context '.jst' do
+ include FakeFS::SpecHelpers
+
+ let(:path) { 'file.jst' }
+ let(:content) { 'content' }
+
+ before do
+ File.open(path, 'wb') { |fh| fh.print content }
+ end
+
+ it 'should use the JST template processor to get the processed file' do
+ subject.should include('JST["file"]')
+ subject.should include(content)
+ end
+ end
+
+ context '.jst.*' do
+ include FakeFS::SpecHelpers
+
+ let(:path) { 'file.jst.ejs' }
+ let(:content) { 'content' }
+
+ before do
+ File.open(path, 'wb') { |fh| fh.print content }
+ end
+
+ it 'should use the JST template processor to get the processed file' do
+ subject.should include('JST["file"]')
+ subject.should include(content)
+ end
+ end
end
describe '#dependencies' do