Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Commit

Permalink
Merge pull request #457 from aendrew/428_support_srcset
Browse files Browse the repository at this point in the history
Adds support for a single srcset item
  • Loading branch information
sindresorhus committed Oct 23, 2014
2 parents 39a7258 + d741232 commit 62abec4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/fileprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ var _defaultPatterns = {
[
/<image[^\>]*[^\>\S]+src=['"]([^"']+)["']/gm,
'Update the HTML with the new image filenames for src links'
],
[
/<(?:img|source)[^\>]*[^\>\S]+srcset=['"]([^"'\s]+)(?:\s\d[mx])["']/gm,
'Update the HTML with the new image filenames for srcset links'
]
],
css: [
Expand Down
10 changes: 10 additions & 0 deletions test/test-fileprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ describe('FileProcessor', function () {
'app/bar.css': 'bar.5678.css',
'app/baz.css': '/baz.8910.css',
'app/image.png': 'image.1234.png',
'app/image@2x.png': 'image@2x.1234.png',
'app/video.webm': 'video.1234.webm',
'tmp/bar.css': 'bar.1234.css',
'app/foo.js': 'foo.1234.js',
Expand Down Expand Up @@ -427,6 +428,15 @@ describe('FileProcessor', function () {
assert.equal(replaced, '<meta name="foo" content="' + filemapping['app/image.png'] + '">');
});

it('should replace img reference in srcset', function () {
var content = '<img srcset="image@2x.png 2x" />';
var replaced = fp.replaceWithRevved(content, ['app']);
assert.equal(replaced, '<img srcset="' + filemapping['app/image@2x.png'] + ' 2x" />');

content = '<source srcset="image@2x.png 2x" />';
replaced = fp.replaceWithRevved(content, ['app']);
assert.equal(replaced, '<source srcset="' + filemapping['app/image@2x.png'] + ' 2x" />');
});
});

describe('css type', function () {
Expand Down

0 comments on commit 62abec4

Please sign in to comment.