Skip to content

Commit

Permalink
use already existing quotation marks - resolves #115
Browse files Browse the repository at this point in the history
stephenplusplus committed Oct 30, 2014
1 parent 609ceee commit c18dd30
Showing 4 changed files with 56 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/inject-dependencies.js
Original file line number Diff line number Diff line change
@@ -56,15 +56,23 @@ function replaceIncludes(file, fileType, returnType) {

var newFileContents = startBlock;
var dependencies = globalDependenciesSorted[blockType] || [];
var quoteMark = '';

(string.substr(0, offset) + string.substr(offset + match.length)).
replace(oldScripts, '').
replace(fileType.block, '').
replace(fileType.detect[blockType], function (match, reference) {
quoteMark = match.match(/['"]/) && match.match(/['"]/)[0];
filesCaught.push(reference.replace(/['"\s]/g, ''));
return match;
});

if (!quoteMark) {
// What the heck. Check if there's anything in the oldScripts block.
match.replace(fileType.detect[blockType], function (match) {
quoteMark = match.match(/['"]/) && match.match(/['"]/)[0];
});
}

spacing = returnType + spacing.replace(/\r|\n/g, '');

dependencies.
@@ -83,6 +91,9 @@ function replaceIncludes(file, fileType, returnType) {
} else if (typeof fileType.replace[blockType] === 'string') {
newFileContents += spacing + fileType.replace[blockType].replace('{{filePath}}', filePath);
}
if (quoteMark) {
newFileContents = newFileContents.replace(/"/g, quoteMark);
}
});

return newFileContents + spacing + endBlock;
16 changes: 16 additions & 0 deletions test/fixture/html/index-detect-quotation-marks-actual.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<title>test.</title>
<script src='../bower_components/modernizr/modernizr.js'></script>
<link rel="stylesheet" href="../bower_components/bootstrap/dist/css/bootstrap.css" />
<!-- bower:css -->
<!-- endbower -->
</head>
<body>

<!-- bower:js -->
<!-- endbower -->
</body>
</html>
20 changes: 20 additions & 0 deletions test/fixture/html/index-detect-quotation-marks-expected.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!doctype html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<title>test.</title>
<script src='../bower_components/modernizr/modernizr.js'></script>
<link rel="stylesheet" href="../bower_components/bootstrap/dist/css/bootstrap.css" />
<!-- bower:css -->
<link rel="stylesheet" href="../bower_components/codecode/dist/codecode.css" />
<!-- endbower -->
</head>
<body>

<!-- bower:js -->
<script src='../bower_components/jquery/jquery.js'></script>
<script src='../bower_components/codecode/dist/codecode.js'></script>
<script src='../bower_components/bootstrap/dist/js/bootstrap.js'></script>
<!-- endbower -->
</body>
</html>
8 changes: 8 additions & 0 deletions test/wiredup_test.js
Original file line number Diff line number Diff line change
@@ -32,6 +32,14 @@ describe('wiredep', function () {
it('should work with unrecognized file types', testReplace('unrecognized'));
it('should correctly handle relative paths', testReplace('html/deep/nested'));

it('should detect and use quotation marks', function () {
var filePaths = getFilePaths('index-detect-quotation-marks', 'html');

wiredep({ src: [filePaths.actual] });

assert.equal(filePaths.read('expected'), filePaths.read('actual'));
});

it('should support globbing', function () {
wiredep({ src: ['html/index-actual.*', 'jade/index-actual.*'] });

0 comments on commit c18dd30

Please sign in to comment.