Skip to content

Commit 4d4b903

Browse files
committed
feat: Find all asset by a regexp filemask or a filepath
+ finding all asset by a regexp filemask, i.e. /\.(?:svg|eot|woff|woff2|gif|ttf)$/ what is required for example for the Foreman
1 parent dba2802 commit 4d4b903

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/sprockets/base.rb

+19
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,25 @@ def find_asset!(*args)
129129
end
130130
end
131131

132+
# Find all asset by a regexp filemask or a filepath.
133+
def find_all_assets(*args, &block)
134+
paths = config[:paths]
135+
136+
args.each do |arg|
137+
if arg.is_a?(Regexp)
138+
paths.each do |path|
139+
files = Dir["#{path}/*"].select {|file| arg =~ file }
140+
141+
files.each do |file|
142+
find_all_linked_assets(file, &block)
143+
end
144+
end
145+
else
146+
find_all_linked_assets(*args, &block)
147+
end
148+
end
149+
end
150+
132151
# Pretty inspect
133152
def inspect
134153
"#<#{self.class}:0x#{object_id.to_s(16)} " +

lib/sprockets/manifest.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def find(*args)
122122
environment = self.environment.cached
123123
promises = args.flatten.map do |path|
124124
Concurrent::Promise.execute(executor: executor) do
125-
environment.find_all_linked_assets(path) do |asset|
125+
environment.find_all_assets(path) do |asset|
126126
yield asset
127127
end
128128
end

0 commit comments

Comments
 (0)