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 13, 2020
1 parent dba2802 commit ebcc1d1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprocket
## Master

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

## 4.0.2

Expand Down
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(arg, &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 ebcc1d1

Please sign in to comment.