mangony-hbs-helpers
Version:
Handlebars helpers used by Mangony
23 lines (20 loc) • 409 B
JavaScript
var fs = require('fs');
module.exports = ifExists;
module.exports.register = function (Handlebars) {
Handlebars.registerHelper('ifExists', ifExists);
};
function fileExists(filepath) {
try {
return fs.statSync(filepath).isFile();
}
catch (err) {
return false;
}
}
function ifExists(path, context) {
if (fileExists(path)) {
return context.fn(this);
} else {
return context.inverse(this);
}
}