Permalink
Browse files

Pass absolute path to each_logical_path filter block

  • Loading branch information...
1 parent 5bef8bb commit 93e5103bc9534aacb9eab09eba199fc67e96fc09 @josh josh committed Oct 16, 2012
Showing with 21 additions and 6 deletions.
  1. +10 −6 lib/sprockets/base.rb
  2. +11 −0 test/test_environment.rb
View
@@ -400,31 +400,35 @@ def circular_call_protection(path)
def logical_path_for_filename(filename, filters)
logical_path = attributes_for(filename).logical_path.to_s
- if matches_filter(filters, logical_path)
+ if matches_filter(filters, logical_path, filename)
return logical_path
end
# If filename is an index file, retest with alias
if File.basename(logical_path)[/[^\.]+/, 0] == 'index'
path = logical_path.sub(/\/index\./, '.')
- if matches_filter(filters, path)
+ if matches_filter(filters, path, filename)
return path
end
end
nil
end
- def matches_filter(filters, filename)
+ def matches_filter(filters, logical_path, filename)
return true if filters.empty?
filters.any? do |filter|
if filter.is_a?(Regexp)
- filter.match(filename)
+ filter.match(logical_path)
elsif filter.respond_to?(:call)
- filter.call(filename)
+ if filter.arity == 1
+ filter.call(logical_path)
+ else
+ filter.call(logical_path, filename.to_s)
+ end
else
- File.fnmatch(filter.to_s, filename)
+ File.fnmatch(filter.to_s, logical_path)
end
end
end
@@ -311,6 +311,17 @@ def self.test(name, &block)
assert !paths.include?("gallery.css")
end
+ test "iterate over each logical path matching proc filters with full path arg" do
+ paths = []
+ @env.each_logical_path(proc { |_, fn| fn.match(fixture_path('default/mobile')) }) do |logical_path|
+ paths << logical_path
+ end
+
+ assert paths.include?("mobile/a.js")
+ assert paths.include?("mobile/b.js")
+ assert !paths.include?("application.js")
+ end
+
test "CoffeeScript files are compiled in a closure" do
script = @env["coffee"].to_s
assert_equal "undefined", ExecJS.exec(script)

0 comments on commit 93e5103

Please sign in to comment.