Skip to content
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

Add srcset option to image_tag helper #29349

Merged
merged 1 commit into from Jul 1, 2017

Conversation

robertomiranda
Copy link
Contributor

Summary

Adding srcset option to image_tag in order to add Responsive Images.

Usage:

image_tag("icon.png", srcset: { 'pic_640.jpg' => '640w', 'pic_1024.jpg' => '1024w', 'pic_1980.jpg' => '1980w' }, sizes: '100vw', class: 'my-image')
#=> <img src="/assets/ants_1980.jpg" srcset="/assets/pic_640.jpg 640w, /assets/pic_1024.jpg 1024w, /assets/pic_1980.jpg 1980w" sizes="100vw" class="my-image">

@rails-bot
Copy link

r? @matthewd

(@rails-bot has picked a reviewer for you, use r? to override)

@matthewd
Copy link
Member

matthewd commented Jun 4, 2017

I think we should respect :skip_pipeline for these images. No need to worry about controlling it separately for each -- just have them all use the value from the main options.

I like that this works with both a hash or an array-of-arrays; let's cover both of those in the tests.

We definitely need to allow a value that's already a string to pass through safely, too, though -- people will already be using it in that way, and we don't want to break them.

@robertomiranda
Copy link
Contributor Author

@matthewd sure, I'll be working on that, thanks for the feedback 😁

@robertomiranda
Copy link
Contributor Author

@matthewd I think is ready again for review, could you take a look again??

@@ -237,6 +243,13 @@ def image_tag(source, options = {})
options[:alt] = options.fetch(:alt) { image_alt(src) }
end

if options[:srcset] && !options[:srcset].is_a?(String)
options[:srcset] = options[:srcset].map do |src, size|
src_path = path_to_image(src, skip_pipeline: options.delete(:skip_pipeline))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleting the option inside the loop here seems like it won't do what you want

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah you are right

@robertomiranda
Copy link
Contributor Author

@matthewd could you take a look again over this PR??

@matthewd matthewd merged commit 43efae2 into rails:master Jul 1, 2017
matthewd added a commit that referenced this pull request Jul 1, 2017
Add srcset option to image_tag helper
@robertomiranda robertomiranda deleted the responsive-images branch July 1, 2017 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants