Skip to content

Commit

Permalink
fix: don't remove wanted whitespace when removing tags (closes #177)
Browse files Browse the repository at this point in the history
  • Loading branch information
joakimbeng committed May 18, 2016
1 parent b4fd0d6 commit 8078cd9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/inject/expected/issue177.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<title>gulp-inject</title>
<link rel="import" href="/fixtures/component.html">
<link rel="stylesheet" href="/fixtures/styles.css">
<link rel="stylesheet" href="/fixtures/morestyles.css">
<link rel="stylesheet" href="/fixtures/andevenmore.css">
</head>
<body>
<img src="/fixtures/image.png">

<script src="/fixtures/lib.js"></script>

<script type="text/jsx" src="/fixtures/lib.jsx"></script>
</body>
</html>
8 changes: 6 additions & 2 deletions src/inject/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ function getNewContent(target, collection, opt) {
endTag: endTag,
tagsToInject: tagsToInject,
removeTags: opt.removeTags,
empty: opt.empty,
willInject: function (filesToInject) {
injectedFilesCount += filesToInject.length;
},
Expand All @@ -151,6 +152,7 @@ function getNewContent(target, collection, opt) {
endTag: endTag,
tagsToInject: [],
removeTags: opt.removeTags,
empty: opt.empty,
shouldAbort: function (match) {
return matches.indexOf(match[0]) !== -1;
}
Expand Down Expand Up @@ -207,8 +209,10 @@ function inject(content, opt) {
var newContents = content.slice(0, startMatch.index);

if (opt.removeTags) {
// Take care of content length change:
startTag.lastIndex -= startMatch[0].length;
if (opt.empty) {
// Take care of content length change:
startTag.lastIndex -= startMatch[0].length;
}
} else {
// <startMatch> + <endMatch>
toInject.unshift(startMatch[0]);
Expand Down
17 changes: 17 additions & 0 deletions src/inject/inject_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,23 @@ describe('gulp-inject', function () {
streamShouldContain(stream, ['removeTags.html'], done);
});

it('should be able to remove tags without removing whitespace (issue #177)', function (done) {
var target = src(['template.html'], {read: true});
var sources = src([
'lib.js',
'component.html',
'styles.css',
'morestyles.css',
'andevenmore.css',
'image.png',
'lib.jsx'
]);

var stream = target.pipe(inject(sources, {removeTags: true}));

streamShouldContain(stream, ['issue177.html'], done);
});

it('should not produce log output if quiet option is set', function (done) {
var logOutput = [];
gutil.log = function () {
Expand Down

0 comments on commit 8078cd9

Please sign in to comment.