Permalink
Browse files

Fixed problem with expanding folder/prefix* wildcards.

  • Loading branch information...
1 parent f12c737 commit d7101d66eb69c91a2e4bbf92f8c3324bab730d3c @jakubpawlowicz committed Apr 15, 2011
Showing with 18 additions and 18 deletions.
  1. +2 −6 lib/assets.js
  2. +15 −11 test/assets-test.js
  3. +1 −1 test/assets/assets.yml
  4. 0 test/assets/stylesheets/folder1/other.css
View
@@ -32,8 +32,8 @@ AssetsExpander.prototype = {
} else if (asset.includes('*')) {
var prefix = '';
if (asset.indexOf('/') >= 0) {
- prefix = asset.substring(0, asset.indexOf('*'));
- asset = '*';
+ prefix = asset.substring(0, asset.lastIndexOf('/'));
+ asset = asset.substring(prefix.length + 1);
}
matches.push(self._scanDir(path.join(root, prefix), asset, false, options.type));
} else {
@@ -102,10 +102,6 @@ AssetsExpander.prototype = {
matches = [],
self = this;
- if (!path.existsSync(root)) {
- root = root.replace(/[^\/]+$/, '');
- }
-
fs.readdirSync(path.join(root, path.dirname(pathToDir))).forEach(function(match) {
var fullPath = path.join(root, match),
stat = fs.lstatSync(fullPath);
View
@@ -95,8 +95,8 @@ exports.listsSuite = vows.describe('expanding assets').addBatch({
},
'expanding multi level wildcard argument': {
topic: expand('**/*'),
- 'should give 7 assets': function(expanded) {
- assert.length(expanded, 7);
+ 'should give 8 assets': function(expanded) {
+ assert.length(expanded, 8);
},
'should give files in proper order': function(expanded) {
assert.equal(expanded[0], fullPathTo('asset1'));
@@ -105,29 +105,32 @@ exports.listsSuite = vows.describe('expanding assets').addBatch({
assert.equal(expanded[3], fullPathTo('other-asset'));
assert.equal(expanded[4], fullPathTo('folder1/asset4'));
assert.equal(expanded[5], fullPathTo('folder1/asset5'));
- assert.equal(expanded[6], fullPathTo('folder1/subfolder1/asset6'));
+ assert.equal(expanded[6], fullPathTo('folder1/other'));
+ assert.equal(expanded[7], fullPathTo('folder1/subfolder1/asset6'));
}
},
'expanding multi level wildcard with prefix': {
topic: expand('folder1/**/*'),
- 'should give 3 assets': function(expanded) {
- assert.length(expanded, 3);
+ 'should give 4 assets': function(expanded) {
+ assert.length(expanded, 4);
},
'should give files in proper order': function(expanded) {
assert.equal(expanded[0], fullPathTo('folder1/asset4'));
assert.equal(expanded[1], fullPathTo('folder1/asset5'));
- assert.equal(expanded[2], fullPathTo('folder1/subfolder1/asset6'));
+ assert.equal(expanded[2], fullPathTo('folder1/other'));
+ assert.equal(expanded[3], fullPathTo('folder1/subfolder1/asset6'));
}
},
'expanding sublevel list': {
topic: expand('folder1/[asset5,subfolder1/*,*]'),
- 'should give 3 assets': function(expanded) {
- assert.length(expanded, 3);
+ 'should give 4 assets': function(expanded) {
+ assert.length(expanded, 4);
},
'should give files in proper order': function(expanded) {
assert.equal(expanded[0], fullPathTo('folder1/asset5'));
assert.equal(expanded[1], fullPathTo('folder1/subfolder1/asset6'));
assert.equal(expanded[2], fullPathTo('folder1/asset4'));
+ assert.equal(expanded[3], fullPathTo('folder1/other'));
}
}
});
@@ -170,13 +173,14 @@ exports.groupsSuite = vows.describe('expanding assets groups').addBatch({
},
'expanding group #4 from assets.yml': {
topic: group('desktop/public4'),
- 'should give 3 assets': function(expanded) {
- assert.length(expanded, 3);
+ 'should give 4 assets': function(expanded) {
+ assert.length(expanded, 4);
},
'should give in proper order': function(expanded) {
assert.equal(expanded[0], fullPathTo('folder1/asset4'));
assert.equal(expanded[1], fullPathTo('folder1/asset5'));
- assert.equal(expanded[2], fullPathTo('folder1/subfolder1/asset6'));
+ assert.equal(expanded[2], fullPathTo('folder1/other'));
+ assert.equal(expanded[3], fullPathTo('folder1/subfolder1/asset6'));
}
}
});
View
@@ -10,6 +10,6 @@ stylesheets:
desktop/public4:
- folder1:
- '*'
- - subfolder1/*'
+ - 'subfolder1/*'
javascripts:
desktop/public1: ''
No changes.

0 comments on commit d7101d6

Please sign in to comment.