diff --git a/lib/jasmine/headless/files_list.rb b/lib/jasmine/headless/files_list.rb index a97f11b..a26c560 100644 --- a/lib/jasmine/headless/files_list.rb +++ b/lib/jasmine/headless/files_list.rb @@ -153,10 +153,10 @@ module Jasmine::Headless register_engine ".#{extension}", Jasmine::Headless::NilTemplate end - register_engine '.coffee', Jasmine::Headless::CoffeeTemplate - register_engine '.js', Jasmine::Headless::JSTemplate - register_engine '.css', Jasmine::Headless::CSSTemplate - register_engine '.jst', Jasmine::Headless::JSTTemplate + # register_engine '.coffee', Jasmine::Headless::CoffeeTemplate + # register_engine '.js', Jasmine::Headless::JSTemplate + # register_engine '.css', Jasmine::Headless::CSSTemplate + # register_engine '.jst', Jasmine::Headless::JSTTemplate end @sprockets_environment @@ -211,7 +211,28 @@ module Jasmine::Headless alert_time = nil end - sprockets_environment.find_asset(file, :bundle => false).body + asset = sprockets_environment.find_asset(file, :bundle => false) + cache_file = File.join('.jhw-cache', 'code', asset.logical_path) + # Process & cache the asset only if needed + unless File.exist?(cache_file) && (File.mtime(file) > File.mtime(cache_file)) + FileUtils.mkdir_p File.dirname(cache_file) + asset.write_to(cache_file) + end + + html = '' + case asset.content_type + when 'application/javascript' + html = %{} + # NOTE: In future sprockets versions below could be simplified w/ asset.extensions.include?('.coffee') + if asset.pathname.basename.to_s.scan(/\.[^.]+/).include?('.coffee') + html += %{\n} + end + when 'text/css' + html = %{} + else + html = asset.body + end + html end.compact.reject(&:empty?) end