Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
**Master**

- Forward keywords through environment and linked asset lookups. [Oskar Eichler](https://github.com/OskarEichler)

Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprockets/blob/master/UPGRADING.md

# 4.4.1
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -714,3 +714,5 @@ Please see the [CHANGELOG](https://github.com/rails/sprockets/tree/master/CHANGE

## License
Sprockets is released under the [MIT License](MIT-LICENSE).

Environment wrappers and linked-asset enumeration forward keyword options, including deferred enumerators. Base#find_asset! additionally needs the existing correction in PR #792.
10 changes: 5 additions & 5 deletions lib/sprockets/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ def find_asset(*args, **options)
end
end

def find_all_linked_assets(*args)
return to_enum(__method__, *args) unless block_given?
def find_all_linked_assets(*args, **options)
return to_enum(__method__, *args, **options) unless block_given?

parent_asset = asset = find_asset(*args)
parent_asset = asset = find_asset(*args, **options)
return unless asset

yield asset
Expand Down Expand Up @@ -126,8 +126,8 @@ def [](*args, **options)
# Find asset by logical path or expanded path.
#
# If the asset is not found an error will be raised.
def find_asset!(*args)
uri, _ = resolve!(*args)
def find_asset!(*args, **options)
uri, _ = resolve!(*args, **options)
if uri
load(uri)
end
Expand Down
8 changes: 4 additions & 4 deletions lib/sprockets/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ def find_asset(*args, **options)
cached.find_asset(*args, **options)
end

def find_asset!(*args)
cached.find_asset!(*args)
def find_asset!(*args, **options)
cached.find_asset!(*args, **options)
end

def find_all_linked_assets(*args, &block)
cached.find_all_linked_assets(*args, &block)
def find_all_linked_assets(*args, **options, &block)
cached.find_all_linked_assets(*args, **options, &block)
end

def load(*args)
Expand Down
7 changes: 7 additions & 0 deletions test/test_environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,13 @@ def self.test(name, &block)
assert_equal [137, 80, 78, 71, 13, 10, 26, 10, 60, 115], asset.to_s[0, 10].bytes.to_a
end

test "find asset bang forwards keyword options" do
asset = @env.find_asset!("logo", accept: "image/svg+xml")

assert_equal "image/svg+xml", asset.content_type
assert_equal "logo.svg", asset.logical_path
end

test "full path svg transformer" do
assert @env.find_asset(fixture_path("default/logo.svg"))
refute @env.find_asset(fixture_path("default/logo.png"))
Expand Down