-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add vite_picture_tag for Rails 7.1 #409
feat: Add vite_picture_tag for Rails 7.1 #409
Conversation
62e7691
to
fa4b1ba
Compare
actioncable (6.1.3.1) | ||
actionpack (= 6.1.3.1) | ||
activesupport (= 6.1.3.1) | ||
actioncable (7.1.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ποΈ I updated the lock file to be able to test against Rails 7.1.0. Let me know if I should split this into a separate commit or PR.
@@ -79,6 +79,17 @@ def vite_image_tag(name, **options) | |||
image_tag(vite_asset_path(name), options) | |||
end | |||
|
|||
if defined?(Rails) && Rails.gem_version >= Gem::Version.new('7.1.0') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π€ I had to add the defined?
check to work around certain test failures. I assume that Rails
will be defined when this file is loaded in a real app. Is there a better way to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That approach would have worked, but changed my mind as I'd like to provide more information in case users see it in the docs and try to use it in an older version of Rails.
Rails 7.1 introduced a `picture_tag` helper.[^1] This commit adds a corresponding `vite_picture_tag` helper that handles resolving assets via Vite, but otherwise behaves the same as `picture_tag`. It is only exposed for Rails >= 7.1.0. [^1]: rails/rails#48100
fa4b1ba
to
a5827d4
Compare
β¦ an older version of Rails
Nice addition, thanks Matt! Released in |
Description π
This commit adds a
vite_picture_tag
helper that handles resolving assets via Vite, but otherwise behaves the same as the Rails built-inpicture_tag
. It is only exposed for Rails >= 7.1.0. Fixes #386Background π
Rails 7.1 introduced a
picture_tag
helper.1The Fix π¨
Added
vite_picture_tag
toViteRails::TagHelpers
with a corresponding test.Footnotes
https://github.com/rails/rails/pull/48100 β©