Permalink
Browse files

Add stub support

  • Loading branch information...
1 parent 8809041 commit 8b0b02f6ae640dd773b4bff19e9d45be4d427211 @aaronjensen aaronjensen committed Apr 7, 2013
Showing with 28 additions and 12 deletions.
  1. +15 −11 lib/sprockets/asset_with_dependencies.rb
  2. +12 −0 test/assets_test.rb
  3. +1 −1 turbo-sprockets-rails3.gemspec
@@ -78,28 +78,32 @@ def hash
private
def build_required_assets(environment, context, asset_options = {})
+ @required_assets = resolve_dependencies(environment, context._required_paths + [pathname.to_s], asset_options) -
+ resolve_dependencies(environment, context._stubbed_assets.to_a, asset_options)
+ end
+
+ def resolve_dependencies(environment, paths, asset_options)
asset_options[:bundle] = false
- @required_assets = []
- required_assets_cache = {}
+ assets = []
+ cache = {}
- (context._required_paths + [pathname.to_s]).each do |path|
+ paths.each do |path|
if path == self.pathname.to_s
- unless required_assets_cache[self]
- required_assets_cache[self] = true
- @required_assets << self
+ unless cache[self]
+ cache[self] = true
+ assets << self
end
elsif asset = environment.find_asset(path, asset_options)
asset.required_assets.each do |asset_dependency|
- unless required_assets_cache[asset_dependency]
- required_assets_cache[asset_dependency] = true
- @required_assets << asset_dependency
+ unless cache[asset_dependency]
+ cache[asset_dependency] = true
+ assets << asset_dependency
end
end
end
end
- required_assets_cache.clear
- required_assets_cache = nil
+ assets
end
def build_dependency_paths(environment, context, asset_options = {})
View
@@ -39,6 +39,18 @@ def assert_no_file_exists(filename)
assert !File.exists?(filename), "#{filename} does exist"
end
+ test "assets support stub" do
+ app_file "app/assets/javascripts/application.js", "//= require jquery\n//= require foo\n//= stub frameworks"
+ app_file "app/assets/javascripts/jquery.js", "jQuery = 1;"
+ app_file "app/assets/javascripts/frameworks.js", "//= require jquery"
+ app_file "app/assets/javascripts/foo.js", "foo = 1;"
+
+ require "#{app_path}/config/environment"
+
+ get "/assets/application.js"
+ assert_equal "foo = 1;", last_response.body.strip
+ end
+
test "assets routes have higher priority" do
app_file "app/assets/javascripts/demo.js.erb", "a = <%= image_path('rails.png').inspect %>;"
@@ -14,6 +14,6 @@ Gem::Specification.new do |s|
s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.md"]
s.test_files = Dir["test/**/*"]
- s.add_runtime_dependency "sprockets", ">= 2.0.0"
+ s.add_runtime_dependency "sprockets", ">= 2.2.0"
s.add_runtime_dependency "railties", "> 3.2.8", '< 4.0.0'
end

0 comments on commit 8b0b02f

Please sign in to comment.