Merge pull request #1500 from dperrymorrow/srcset-support
Pull request for issue #1396 supporting srcset property in image tags
This commit is contained in:
commit
07eca1e560
7
middleman-core/features/image_srcset_paths.feature
Normal file
7
middleman-core/features/image_srcset_paths.feature
Normal file
|
@ -0,0 +1,7 @@
|
|||
Feature: Support srcset property as params for image_tag helper
|
||||
This lets you specify responsive image sizes
|
||||
|
||||
Scenario: Rendering an image with the feature enabled
|
||||
Given the Server is running at "image-srcset-paths-app"
|
||||
When I go to "/image-srcset-paths.html"
|
||||
Then I should see '//example.com/remote-image.jpg 2x, /images/blank_3x.jpg 3x'
|
|
@ -33,9 +33,10 @@ Feature: Markdown support in Haml (Kramdown)
|
|||
:markdown
|
||||
[A link](/link_target.html)
|
||||
|
||||
![image](blank.gif)
|
||||
![image](blank.gif){: srcset="image_2x.jpg 2x"}
|
||||
"""
|
||||
Given the Server is running at "markdown-in-haml-app"
|
||||
When I go to "/link_and_image/"
|
||||
Then I should see "/link_target/"
|
||||
Then I should see "/images/image_2x.jpg 2x"
|
||||
Then I should see 'src="/images/blank.gif"'
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<%= image_tag 'blank.jpg', srcset: '//example.com/remote-image.jpg 2x, blank_3x.jpg 3x, http://example.com/remoteimage.jpg 4x' %>
|
BIN
middleman-core/fixtures/image-srcset-paths-app/images/blank.gif
Executable file
BIN
middleman-core/fixtures/image-srcset-paths-app/images/blank.gif
Executable file
Binary file not shown.
After Width: | Height: | Size: 43 B |
|
@ -255,5 +255,18 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension
|
|||
url = url_for(url, options)
|
||||
super
|
||||
end
|
||||
|
||||
# Modified Padrino image_tag so that it finds the paths for srcset
|
||||
# using asset_path for the images listed in the srcset param
|
||||
def image_tag(path, params={})
|
||||
params.symbolize_keys!
|
||||
|
||||
if params.key?(:srcset)
|
||||
images = params[:srcset].split(',').map {|size| (size.include?('//') ? size : asset_url("images/#{size.strip}")) }
|
||||
params[:srcset] = images.join(', ')
|
||||
end
|
||||
|
||||
super(path, params)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue