Skip to content

Commit

Permalink
move logAndRenderError to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
ernscht committed Mar 19, 2016
1 parent 32dc4f7 commit dcfc651
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
11 changes: 10 additions & 1 deletion app/templates/app/core/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var fs = require('fs');
var hbs = require('hbs');

function fileExistsSync(filename) {
// Substitution for the deprecated fs.existsSync() method @see https://nodejs.org/api/fs.html#fs_fs_existssync_path
Expand All @@ -11,6 +12,14 @@ function fileExistsSync(filename) {
}
}

function logAndRenderError(e) {
console.info(e.message);
return new hbs.handlebars.SafeString(
'<p class="nitro-msg nitro-msg--error">' + e.message + '</p>'
);
}

module.exports = {
fileExistsSync: fileExistsSync
fileExistsSync: fileExistsSync,
logAndRenderError: logAndRenderError
};
9 changes: 1 addition & 8 deletions app/templates/app/helpers/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ var utils = require('../core/utils');

module.exports = function () {

var logAndRenderError = function logAndRenderError(e) {
console.info(e.message);
return new hbs.handlebars.SafeString(
'<p class="nitro-msg nitro-msg--error">' + e.message + '</p>'
);
};

try {
var context = arguments[arguments.length - 1];
var contextDataRoot = context.data && context.data.root ? context.data.root : {}; // default component data from controller & view
Expand Down Expand Up @@ -98,6 +91,6 @@ module.exports = function () {
throw new Error('Component `' + name + '` with template file `'+ templateFile + '.' + cfg.nitro.view_file_extension + '` not found in folder `' + folder + '`.');
}
catch (e) {
return logAndRenderError(e);
return utils.logAndRenderError(e);
}
};

0 comments on commit dcfc651

Please sign in to comment.