diff --git a/lib/jasmine/headless.rb b/lib/jasmine/headless.rb index 9af2e94..a1dae0b 100644 --- a/lib/jasmine/headless.rb +++ b/lib/jasmine/headless.rb @@ -2,6 +2,9 @@ require 'pathname' module Jasmine module Headless + + EXCLUDED_FORMATS = %w{less sass scss erb str} + autoload :CommandLine, 'jasmine/headless/command_line' autoload :CoffeeScriptCache, 'jasmine/headless/coffee_script_cache' @@ -16,11 +19,14 @@ module Jasmine autoload :UniqueAssetList, 'jasmine/headless/unique_asset_list' autoload :TemplateWriter, 'jasmine/headless/template_writer' + + autoload :FileChecker, 'jasmine/headless/file_checker' autoload :CoffeeTemplate, 'jasmine/headless/coffee_template' autoload :JSTemplate, 'jasmine/headless/js_template' autoload :JSTTemplate, 'jasmine/headless/jst_template' autoload :CSSTemplate, 'jasmine/headless/css_template' + autoload :NilTemplate, 'jasmine/headless/nil_template' autoload :Report, 'jasmine/headless/report' autoload :ReportMessage, 'jasmine/headless/report_message' diff --git a/lib/jasmine/headless/coffee_template.rb b/lib/jasmine/headless/coffee_template.rb index a63db16..cfaaec2 100644 --- a/lib/jasmine/headless/coffee_template.rb +++ b/lib/jasmine/headless/coffee_template.rb @@ -3,11 +3,17 @@ require 'rainbow' module Jasmine::Headless class CoffeeTemplate < Tilt::Template + include Jasmine::Headless::FileChecker + self.default_mime_type = 'application/javascript' def prepare ; end def evaluate(scope, locals, &block) + if bad_format?(file) + alert_bad_format(file) + return '' + end begin cache = Jasmine::Headless::CoffeeScriptCache.new(file) source = cache.handle diff --git a/lib/jasmine/headless/css_template.rb b/lib/jasmine/headless/css_template.rb index 7829548..7053772 100644 --- a/lib/jasmine/headless/css_template.rb +++ b/lib/jasmine/headless/css_template.rb @@ -2,11 +2,16 @@ require 'tilt/template' module Jasmine::Headless class CSSTemplate < Tilt::Template + include Jasmine::Headless::FileChecker self.default_mime_type = 'text/css' def prepare ; end def evaluate(scope, locals, &block) + if bad_format?(file) + alert_bad_format(file) + return '' + end file ? %{} : data end end diff --git a/lib/jasmine/headless/file_checker.rb b/lib/jasmine/headless/file_checker.rb new file mode 100644 index 0000000..749f054 --- /dev/null +++ b/lib/jasmine/headless/file_checker.rb @@ -0,0 +1,10 @@ +module Jasmine::Headless::FileChecker + def bad_format?(file) + return if file.nil? + ::Jasmine::Headless::EXCLUDED_FORMATS.any? {|format| file.include?(".#{format}") } + end + + def alert_bad_format(file) + puts "[%s] %s: %s" % [ 'Skipping File'.color(:red), file.color(:yellow), "unsupported format".color(:white) ] + end +end \ No newline at end of file diff --git a/lib/jasmine/headless/files_list.rb b/lib/jasmine/headless/files_list.rb index b34af7d..1c8a069 100644 --- a/lib/jasmine/headless/files_list.rb +++ b/lib/jasmine/headless/files_list.rb @@ -6,6 +6,7 @@ require 'sprockets' require 'sprockets/engines' module Jasmine::Headless + class FilesList class << self def vendor_asset_paths @@ -39,8 +40,8 @@ module Jasmine::Headless # ...and unregister ones we don't want/need Sprockets.instance_eval do - %w{less sass scss erb str}.each do |extension| - @engines.delete(".#{extension}") + EXCLUDED_FORMATS.each do |extension| + register_engine ".#{extension}", Jasmine::Headless::NilTemplate end register_engine '.coffee', Jasmine::Headless::CoffeeTemplate diff --git a/lib/jasmine/headless/js_template.rb b/lib/jasmine/headless/js_template.rb index 0e31fb1..49eb5b6 100644 --- a/lib/jasmine/headless/js_template.rb +++ b/lib/jasmine/headless/js_template.rb @@ -2,11 +2,16 @@ require 'tilt/template' module Jasmine::Headless class JSTemplate < Tilt::Template + include Jasmine::Headless::FileChecker self.default_mime_type = 'application/javascript' def prepare ; end def evaluate(scope, locals, &block) + if bad_format?(file) + alert_bad_format(file) + return '' + end if data[%r{^} end end diff --git a/lib/jasmine/headless/nil_template.rb b/lib/jasmine/headless/nil_template.rb new file mode 100644 index 0000000..eb6a5f1 --- /dev/null +++ b/lib/jasmine/headless/nil_template.rb @@ -0,0 +1,14 @@ +require 'tilt/template' +require 'rainbow' + +module Jasmine::Headless + class NilTemplate < Tilt::Template + + def prepare ; end + + def evaluate(scope, locals, &block) + return '' + end + end +end + diff --git a/spec/integration/sprockets_spec.rb b/spec/integration/sprockets_spec.rb index 792d488..19f8cd6 100644 --- a/spec/integration/sprockets_spec.rb +++ b/spec/integration/sprockets_spec.rb @@ -4,8 +4,8 @@ describe 'sprockets' do it 'should pull in the code via sprockets' do files = %x{bin/jasmine-headless-webkit -l -j spec/jasmine/with_sprockets_includes/with_sprockets_includes.yml} $?.exitstatus.should == 0 - files.lines.to_a.should contain_in_order_in_file_list( + 'assets/application.js.erb: unsupported format', 'vendor/assets/javascripts/jquery.js', 'templates/that.jst.ejs', 'templates/this.jst', diff --git a/spec/lib/jasmine/headless/file_checker_spec.rb b/spec/lib/jasmine/headless/file_checker_spec.rb new file mode 100644 index 0000000..571a73d --- /dev/null +++ b/spec/lib/jasmine/headless/file_checker_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' + +describe Jasmine::Headless::FileChecker do + include FakeFS::SpecHelpers + + let(:test_class) do + object = Object.new + object.class.send(:include, Jasmine::Headless::FileChecker) + object + end + + context "bad_format?" do + it "should return false wth correct format" do + test_class.bad_format?('foobar.js').should be_false + end + it "should return false wth wrong format" do + test_class.bad_format?('foobar.js.erb').should be_true + end + end + + +end diff --git a/spec/lib/jasmine/headless/nil_template_spec.rb b/spec/lib/jasmine/headless/nil_template_spec.rb new file mode 100644 index 0000000..0c0a886 --- /dev/null +++ b/spec/lib/jasmine/headless/nil_template_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe Jasmine::Headless::NilTemplate do + include FakeFS::SpecHelpers + + let(:template) { described_class.new(file) { data } } + let(:file) { 'file' } + let(:data) { '' } + + subject { template.render } + + before do + File.open(file, 'wb') if file + end + + context "no file'" do + let(:file) { nil } + + it { should == data } + end + + context 'file' do + it { should == '' } + end + + context 'script as first thing' do + let(:data) { '' } + + it { should == data } + end +end