inline_svg
inline_svg copied to clipboard
support implicit "media/images" for webpack inline_svg_pack_tag
Hi! What do you think of support the folders "media/images" as the webpacker helper image_pack_tag does?
In the implementation of webpacker helpers, it has the following code:
def resolve_path_to_image(name)
path = name.starts_with?("media/images/") ? name : "media/images/#{name}"
asset_path(current_webpacker_instance.manifest.lookup!(path))
rescue
asset_path(current_webpacker_instance.manifest.lookup!(name))
end
Maybe we can do something similar with InlineSvg::WebpackAssetFinder like this, or try to use the resolve_path_to_image method of webpacker:
module InlineSvg
class WebpackAssetFinder
def self.find_asset(filename)
...
end
def initialize(filename)
@filename = filename.starts_with?('media/images/') ? filename : "media/images/#{filename}"
end
def pathname
...
end
end
end
@felipefava thanks for opening this issue. ✨
I'm not against the idea of supporting a Webpacker convention if it makes the experience better for users of this library. 👍
If you want to open a PR with your proposed changes that would be great. Otherwise it will probably take me a while to get around to this myself.
Yeah, I think It's nice for consistency between the helper image_pack_tag and inline_svg_pack_tag.
I mean, if in some part of the code I use image_pack_tag 'my_folder/my_image.png', I would also expect to use inline_svg_pack_tag 'my_folder/my_svg.svg' instead of inline_svg_pack_tag 'media/images/my_folder/my_svg.svg.
These next days I will be really busy, but I would definitely try to open a PR next month. Thanks for the reply.
I mean, if in some part of the code I use
image_pack_tag 'my_folder/my_image.png', I would also expect to useinline_svg_pack_tag 'my_folder/my_svg.svg'instead ofinline_svg_pack_tag 'media/images/my_folder/my_svg.svg.
Makes sense to me. 👍