Skip to content

Commit

Permalink
feat: Find all asset by a regexp filemask or a filepath
Browse files Browse the repository at this point in the history
+ finding all asset by a regexp filemask,
  i.e. /\.(?:svg|eot|woff|woff2|gif|ttf)$/
  what is required for example for the Foreman
  • Loading branch information
majioa committed Dec 9, 2020
1 parent dba2802 commit 4d4b903
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions lib/sprockets/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,25 @@ def find_asset!(*args)
end
end

# Find all asset by a regexp filemask or a filepath.
def find_all_assets(*args, &block)
paths = config[:paths]

args.each do |arg|
if arg.is_a?(Regexp)
paths.each do |path|
files = Dir["#{path}/*"].select {|file| arg =~ file }

files.each do |file|
find_all_linked_assets(file, &block)
end
end
else
find_all_linked_assets(*args, &block)
end
end
end

# Pretty inspect
def inspect
"#<#{self.class}:0x#{object_id.to_s(16)} " +
Expand Down
2 changes: 1 addition & 1 deletion lib/sprockets/manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def find(*args)
environment = self.environment.cached
promises = args.flatten.map do |path|
Concurrent::Promise.execute(executor: executor) do
environment.find_all_linked_assets(path) do |asset|
environment.find_all_assets(path) do |asset|
yield asset
end
end
Expand Down

0 comments on commit 4d4b903

Please sign in to comment.