diff --git a/middleman-core/features/image_srcset_paths.feature b/middleman-core/features/image_srcset_paths.feature new file mode 100644 index 00000000..b6b1046c --- /dev/null +++ b/middleman-core/features/image_srcset_paths.feature @@ -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' \ No newline at end of file diff --git a/middleman-core/features/markdown_kramdown_in_haml.feature b/middleman-core/features/markdown_kramdown_in_haml.feature index 5b5a5871..5980e1b7 100644 --- a/middleman-core/features/markdown_kramdown_in_haml.feature +++ b/middleman-core/features/markdown_kramdown_in_haml.feature @@ -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"' diff --git a/middleman-core/fixtures/image-srcset-paths-app/image-srcset-paths.html.erb b/middleman-core/fixtures/image-srcset-paths-app/image-srcset-paths.html.erb new file mode 100755 index 00000000..b5fba613 --- /dev/null +++ b/middleman-core/fixtures/image-srcset-paths-app/image-srcset-paths.html.erb @@ -0,0 +1 @@ +<%= image_tag 'blank.jpg', srcset: '//example.com/remote-image.jpg 2x, blank_3x.jpg 3x, http://example.com/remoteimage.jpg 4x' %> \ No newline at end of file diff --git a/middleman-core/fixtures/image-srcset-paths-app/images/blank.gif b/middleman-core/fixtures/image-srcset-paths-app/images/blank.gif new file mode 100755 index 00000000..2498f1aa Binary files /dev/null and b/middleman-core/fixtures/image-srcset-paths-app/images/blank.gif differ diff --git a/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb b/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb index 56daaa28..e711c234 100644 --- a/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb +++ b/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb @@ -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