Possibility to register multiple extensions such as '.coffee.md' Add the new registered_file_extension function Solve issue #830

This commit is contained in:
mquandalle
2013-03-20 23:45:32 +01:00
committed by Nick Martin
parent 2aec0f636c
commit 72482ec07c
2 changed files with 21 additions and 5 deletions

View File

@@ -187,9 +187,9 @@ _.extend(PackageBundlingInfo.prototype, {
return;
self.files[where][rel_path] = true;
var ext = path.extname(rel_path).substr(1);
var handler = self.get_source_handler(ext);
if (handler) {
var ext = files.registered_file_extension(rel_path, self.api.registered_extensions());
if (!! ext) {
var handler = self.get_source_handler(ext.substr(1));
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 (_.indexOf(extensions, path.extname(filepath)) !== -1) {
} else if (!! files.registered_file_extension(filepath, extensions)) {
func(filepath);
}
});
@@ -101,13 +101,29 @@ var files = module.exports = {
ret = ret.concat(files.file_list_sync(
path.join(filepath, fileName), extensions));
});
} else if (_.indexOf(extensions, path.extname(filepath)) !== -1) {
} else if (!! files.registered_file_extension(filepath, extensions)) {
ret.push(filepath);
}
return ret;
},
// Given a path, return his file extension.
// Return false if there are no registered extensions that match.
// This function support multiple extensions such as `.coffee.md`
// unlike the node native `path.extname` function
registered_file_extension: function(filepath, extsList) {
parts = filepath.split('.');
ext = "";
for (var i = parts.length - 1; i > 0; i--) {
ext = '.' + parts[i] + ext;
if (_.indexOf(extsList, ext) !== -1) {
return ext;
}
}
return false;
},
// given a path, returns true if it is a meteor application (has a
// .meteor directory with a 'packages' file). false otherwise.
is_app_dir: function (filepath) {