Skip to content

Commit ebcc1d1

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 ebcc1d1

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprocket
55
## Master
66

77
- Remove remaining support for Ruby < 2.4.[#672](https://github.com/rails/sprockets/pull/672)
8+
- Find all asset by a regexp filemask or a filepath.[#698](https://github.com/rails/sprockets/pull/698)
89

910
## 4.0.2
1011

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(arg, &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)