Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,20 @@ AssetRewrite.prototype.rewriteAssetPath = function (string, assetPath, replaceme
*
* Uses a regular expression to find assets in html tags, css backgrounds, handlebars pre-compiled templates, etc.
*
* ["\'(=] - Match one of "'(= exactly one time
* ["\'(=,] - Match one of "'(=, exactly one time - the comma matches the end of the previous path inside a srcset
* \\s* - Any amount of white space
* ( - Starts the first capture group
* [^"\'()=]* - Do not match any of ^"'()= 0 or more times
* [^"\'()\\>=]* - Do not match any of ^"'()\>= 0 or more times - Explicitly add \ here because of handlebars compilation
* [^"\'()=,]* - Do not match any of ^"'()=, 0 or more times
* [^"\'()\\>=,]* - Do not match any of ^"'()\>= 0 or more times - Explicitly add \ here because of handlebars compilation
* ) - End first capture group
* (\\?[^"\')> ]*)? - Allow for query parameters to be present after the URL of an asset
* \\s* - Any amount of white space
* \\\\* - Allow any amount of \ - For handlebars compilation (includes \\\)
* \\s* - Any amount of white space
* ["\')> ] - Match one of "'( > exactly one time
* ["\')> ,] - Match one of "'( >, exactly one time
*/

var re = new RegExp('["\'(=]\\s*([^"\'()=]*' + escapeRegExp(assetPath) + '[^"\'()\\>=]*)(\\?[^"\')> ]*)?\\s*\\\\*\\s*["\')> ]', 'g');
var re = new RegExp('["\'(=,]\\s*([^"\'()=,]*' + escapeRegExp(assetPath) + '[^"\'()\\>=,]*)(\\?[^"\')> ]*)?\\s*\\\\*\\s*["\')> ,]', 'g');
var match = null;
/*
* This is to ignore matches that should not be changed
Expand Down
18 changes: 18 additions & 0 deletions tests/filter-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,22 @@ describe('broccoli-asset-rev', function() {
confirmOutput(graph.directory, sourcePath + '/output');
})
});

it('handles srcset', function () {
var sourcePath = 'tests/fixtures/srcset';
debugger
var node = new AssetRewrite(sourcePath + '/input', {
assetMap: {
'/images/my-folder/my-image.png': '/images/my-folder/my-image-fingerprinted.png',
'/images/my-folder/my-image_@1.5x.png': '/images/my-folder/my-image-fingerprinted_@1.5x.png',
'/images/my-folder/my-image_@150w.png': '/images/my-folder/my-image-fingerprinted_@150w.png'
},
prepend: 'https://cloudfront.net/'
});

builder = new broccoli.Builder(node);
return builder.build().then(function (graph) {
confirmOutput(graph.directory, sourcePath + '/output');
});
});
});
4 changes: 4 additions & 0 deletions tests/fixtures/srcset/input/img-tag.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<img src="/images/my-folder/my-image.png" srcset="/images/my-folder/my-image.png 1x, /images/my-folder/my-image_@1.5x.png 1.5x" />
<img src="/images/my-folder/my-image.png" srcset="/images/my-folder/my-image.png 100w, /images/my-folder/my-image_@150w.png 150w" />
<img src="/images/my-folder/my-image.png" srcset="/images/my-folder/my-image.png1x, /images/my-folder/my-image_@1.5x.png1.5x" />
<img src="/images/my-folder/my-image.png" srcset="/images/my-folder/my-image.png100w, /images/my-folder/my-image_@150w.png150w" />
4 changes: 4 additions & 0 deletions tests/fixtures/srcset/output/img-tag.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<img src="https://cloudfront.net/images/my-folder/my-image-fingerprinted.png" srcset="https://cloudfront.net/images/my-folder/my-image-fingerprinted.png 1x, https://cloudfront.net/images/my-folder/my-image-fingerprinted_@1.5x.png 1.5x" />
<img src="https://cloudfront.net/images/my-folder/my-image-fingerprinted.png" srcset="https://cloudfront.net/images/my-folder/my-image-fingerprinted.png 100w, https://cloudfront.net/images/my-folder/my-image-fingerprinted_@150w.png 150w" />
<img src="https://cloudfront.net/images/my-folder/my-image-fingerprinted.png" srcset="https://cloudfront.net/images/my-folder/my-image-fingerprinted.png1x, https://cloudfront.net/images/my-folder/my-image-fingerprinted_@1.5x.png1.5x" />
<img src="https://cloudfront.net/images/my-folder/my-image-fingerprinted.png" srcset="https://cloudfront.net/images/my-folder/my-image-fingerprinted.png100w, https://cloudfront.net/images/my-folder/my-image-fingerprinted_@150w.png150w" />