lib/middleman/jasmine/jasmine_sprockets_proxy.rb in middleman-jasmine-0.3.0 vs lib/middleman/jasmine/jasmine_sprockets_proxy.rb in middleman-jasmine-0.4.0
- old
+ new
@@ -8,11 +8,11 @@
def sprockets_app
@@sprockets_app
end
- def configure(middleman_sprockets, config_file = nil)
+ def configure(middleman_sprockets, config_file, debug_assets)
raise "Config file not found" unless valid_config_file?(config_file)
Jasmine.load_configuration_from_yaml(config_file)
@@jasmine_app = Jasmine::Application.app(Jasmine.config)
@@sprockets_app =
if defined?(::Sprockets::Environment)
@@ -23,10 +23,14 @@
sprockets.append_path(Jasmine.config.spec_dir)
sprockets
else
@@jasmine_app
end
+
+ if debug_assets
+ Jasmine.config.add_path_mapper(lambda { |config| DebugAssetMapper.new(@@sprockets_app) } )
+ end
end
private
def valid_config_file?(config_file)
@@ -72,7 +76,22 @@
{ 'Content-Type' => 'text/html'},
[@page.render]
]
end
end
+ end
+end
+
+class DebugAssetMapper
+ attr_reader :sprockets
+ def initialize(sprockets)
+ @sprockets = sprockets
+ end
+
+ def map_spec_paths(spec_paths)
+ spec_paths.map do |path|
+ sprockets[File.basename(path)].to_a.map do | dependency |
+ "/__spec__/#{dependency.logical_path}?body=t"
+ end
+ end.flatten.uniq
end
end