Skip to content

Commit

Permalink
Supporting absolute search paths
Browse files Browse the repository at this point in the history
  • Loading branch information
timdp authored and Tim De Pauw committed Aug 6, 2015
1 parent 76d2eea commit 4eee0ef
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ var gutil = require('gulp-util'),
multimatch = require('multimatch');

function getSearchPaths(cwd, searchPath, filepath) {
// Assuming all paths are relative, strip off leading slashes
filepath = filepath.replace(/^\/+/, '');
// Check for multiple search paths within the array
if (searchPath.indexOf(',') !== -1) {
return searchPath.split(',').map(function (nestedSearchPath) {
return path.join(cwd, nestedSearchPath, filepath);
return path.resolve(cwd, nestedSearchPath, filepath);
});
} else {
return path.join(cwd, searchPath, filepath);
return path.resolve(cwd, searchPath, filepath);
}
}

Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/absolute-search-path.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<!-- build:css /css/combined.css -->
<link href="one.css" rel="stylesheet">
<link href="two.css" rel="stylesheet">
<!-- endbuild -->
</head>
</html>
27 changes: 27 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,33 @@ describe('useref.assets()', function() {
stream.end();
});

it('should understand absolute search paths', function(done) {
var a = 0;

var testFile = getFixture('absolute-search-path.html');

var searchPath = path.join(__dirname, 'fixtures', 'css');

var stream = useref.assets({
searchPath: searchPath
});

stream.on('data', function(newFile){
should.exist(newFile.contents);
newFile.path.should.equal(path.normalize('./test/fixtures/css/combined.css'));
++a;
});

stream.once('end', function () {
a.should.equal(1);
done();
});

stream.write(testFile);

stream.end();
});

it('should not explode on custom blocks', function (done) {
var stream = useref.assets();

Expand Down

0 comments on commit 4eee0ef

Please sign in to comment.