Stylistic cleanups and finding on other place that needs findExtension

This commit is contained in:
Nick Martin
2013-03-22 16:23:03 -07:00
parent 1ef7e770b0
commit c905c7b001
3 changed files with 10 additions and 20 deletions

View File

@@ -150,10 +150,9 @@ _.extend(PackageBundlingInfo.prototype, {
// found in this package. We'll use handlers that are defined in
// this package and in its immediate dependencies. ('extension'
// should be the extension of the file without a leading dot.)
get_source_handler: function (filepath) {
get_source_handler: function (extension) {
var self = this;
var candidates = [];
var extension = files.extname(filepath);
if (extension in self.pkg.extensions)
candidates.push(self.pkg.extensions[extension]);
@@ -188,9 +187,9 @@ _.extend(PackageBundlingInfo.prototype, {
return;
self.files[where][rel_path] = true;
var handler = self.get_source_handler(rel_path);
if (!! handler) {
var ext = files.findExtension(self.api.registered_extensions(), rel_path);
var handler = ext && self.get_source_handler(ext.substr(1));
if (handler) {
handler(self.bundle.api,
path.join(self.pkg.source_root, rel_path),
path.join(self.pkg.serve_root, rel_path),

View File

@@ -85,7 +85,7 @@ var files = module.exports = {
extensions, func);
});
});
} else if (!! files.findExtension(extensions, filepath)) {
} else if (files.findExtension(extensions, filepath)) {
func(filepath);
}
});
@@ -101,7 +101,7 @@ var files = module.exports = {
ret = ret.concat(files.file_list_sync(
path.join(filepath, fileName), extensions));
});
} else if (!! files.findExtension(extensions, filepath)) {
} else if (files.findExtension(extensions, filepath)) {
ret.push(filepath);
}
@@ -109,25 +109,16 @@ var files = module.exports = {
},
// given a list of extensions and a path, return the file extension
// provided in the list. If it doesn't find it, return false.
// provided in the list. If it doesn't find it, return null.
findExtension: function (extensions, filepath) {
var len = filepath.length;
for (var i = 0; i < extensions.length; ++i) {
ext = extensions[i];
var ext = extensions[i];
if (filepath.indexOf(ext, len - ext.length) !== -1){
return ext;
}
}
return false;
},
// given a path, return his file extension, unlike the node native
// `path.extname` function, this function support multiple extensions
// such as `.coffee.md`. false otherwise.
extname: function (filepath) {
var basename = path.basename(filepath);
return basename.substring(basename.indexOf('.') + 1);
return null;
},
// given a path, returns true if it is a meteor application (has a

View File

@@ -507,7 +507,7 @@ _.extend(DependencyWatcher.prototype, {
// Source files
if (in_any_dir(self.source_dirs) &&
_.indexOf(self.source_extensions, path.extname(filepath)) !== -1)
files.findExtension(self.source_extensions, filepath))
return true;
// Other directories and files that are included