inline_svg
inline_svg copied to clipboard
Added new method to check if path starts with media or add it
At this time the Webpacker.manifest.lookup check the correct path of the file. If you not specify the path prepended with media, the Webpacker return nil.
I've added a new method to check if the filename starts with media, otherwise add it.
From the discussion on #109, should the behavior be updated to match image_pack_tag?
https://github.com/rails/webpacker/blob/4565b843f649842b03c99fd877e6f3681dd92027/lib/webpacker/helper.rb#L149-L154
def resolve_path_to_image(name, **options)
path = name.starts_with?("media/images/") ? name : "media/images/#{name}"
path_to_asset(current_webpacker_instance.manifest.lookup!(path), options)
rescue
path_to_asset(current_webpacker_instance.manifest.lookup!(name), options)
end
Essentially rather than just looking for media, check instead for media/images?
rather than just looking for
media, check instead formedia/images?
@clinejj thanks for the suggestion. I don't have a strong opinion on this one, as I don't really use Webpacker in any projects currently. I'm happy to defer to others on this. 🤷
Just wanted to mention, that image_pack_tag uses the "static/" prefix now, and not "media/images": https://github.com/rails/webpacker/blob/master/lib/webpacker/helper.rb#L156