Support both Sprockets and Webpacker #103
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See discussion at #102 for context.
This PR introduces two new helpers
inline_svg_tag
andinline_svg_pack_tag
which will search for SVG files using Sprockets and Webpacker, respectively.The logic for finding and rendering an SVG has been moved into a private method,
render_inline_svg
.The
inline_svg
helper will continue to function as expected (uses any configuredasset_finder
), but now raises a deprecation warning:However, because the behavior of
inline_svg
is effectively unchanged, there may be no need to deprecate it at all!How it works
Under the hood we have a new method,
with_asset_finder
, which is passed a finder class (ornil
) and a block. Calls torender_inline_svg
within the block will use the finder passed towith_asset_finder
.This allows us to temporarily change
InlineSvg.configuration.asset_finder
for the duration of the block, which is how we're able to keep the existinginline_svg
helper backwards-compatible.Disclaimer: I have limited familiarity with the internal guts of this gem, so it's entirely possible that altering
InlineSvg.configuration.asset_finder
as I've done has side-effects on other parts of the gem's functionality. All the tests still pass, so I'm hoping there are no side-effects I've overlooked 🤞I'll add tests for everything if this general approach is approved 👍