require 'rainbow' require 'sprockets' module Jasmine::Headless class TestFile attr_reader :path, :source_root def initialize(path, source_root = nil) @path, @source_root = path, source_root end def ==(other) self.path == other.path end def to_html process_data_by_filename(path) end def dependencies return @dependencies if @dependencies processor = Sprockets::DirectiveProcessor.new(path) @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 ] end end def logical_path path.gsub(%r{^#{source_root}/}, '').gsub(%r{\..+$}, '') end private def read File.read(path) end def process_data_by_filename(path, data = nil) case extension = File.extname(path) when '' data || '' when '.js' data || %{} when '.css' data || %{} else if engine = Sprockets.engines(extension) data = engine.new(path) { data || read }.render(self) data = %{} if extension == '.jst' process_data_by_filename(path.gsub(%r{#{extension}$}, ''), data) else data || '' end end end end end