Skip to content

Commit

Permalink
Special replacement patterns fix (#48)
Browse files Browse the repository at this point in the history
* Special replacement patterns fix

Specifying a function as a parameter do not apply special replacement patterns:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_string_as_a_parameter
Signed-off-by: Vitaliy Khamin <vitaliykhamin@gmail.com>

* Stream special replacement pattern test

Signed-off-by: Vitaliy Khamin <vitaliykhamin@gmail.com>
  • Loading branch information
khamin authored and VFK committed Jun 17, 2016
1 parent 8591aa4 commit 5421df7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ Parser.prototype._transform = function (chunk, enc, done) {
var matches = common.regexMatchAll(content, regex);
matches.forEach(function (match) {
var block = new Block(this.config, this.file, match);
content = content.replace(block.replacement, block.compile(this.tasks));
content = content.replace(block.replacement, function () {
return block.compile(this.tasks)
}.bind(this));
}.bind(this));

done(null, content);
Expand Down
3 changes: 3 additions & 0 deletions test/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ describe('Buffer mode', function () {
'stream-simple': stringToStream('Stream simple replacement').pipe(source('fake-vinyl.txt')),
'stream-advanced': {
src: stringToStream('Stream advanced replacement').pipe(source('fake-vinyl.txt'))
},
'stream-special': {
src: stringToStream('Stream $$ special replacement pattern').pipe(source('fake-vinyl.txt'))
}
});

Expand Down
2 changes: 2 additions & 0 deletions test/expected.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@
Stream simple replacement

Stream advanced replacement

Stream $$ special replacement pattern
</body>
</html>
3 changes: 3 additions & 0 deletions test/fixture.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,8 @@

<!-- build:stream-advanced -->
<!-- endbuild -->

<!-- build:stream-special -->
<!-- endbuild -->
</body>
</html>
3 changes: 3 additions & 0 deletions test/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ describe('Stream mode', function () {
'stream-simple': stringToStream('Stream simple replacement').pipe(source('fake-vinyl.txt')),
'stream-advanced': {
src: stringToStream('Stream advanced replacement').pipe(source('fake-vinyl.txt'))
},
'stream-special': {
src: stringToStream('Stream $$ special replacement pattern').pipe(source('fake-vinyl.txt'))
}
});

Expand Down

0 comments on commit 5421df7

Please sign in to comment.