Skip to content

Commit

Permalink
Clean up formatting of render function
Browse files Browse the repository at this point in the history
  • Loading branch information
gakimball committed Dec 4, 2015
1 parent 3d4477f commit c956e27
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,23 @@ module.exports = function(file, enc, cb) {
this.Handlebars.registerPartial('body', pageTemplate);
file.contents = new Buffer(layoutTemplate(pageData));

} catch (e) {

if(layoutTemplate){
// Layout was parsed properly so we can insert the error message into the body of the layout
this.Handlebars.registerPartial('body', 'Panini error: template could not be parsed <br> \n <pre>{{error}}</pre>');
file.contents = new Buffer(layoutTemplate({error:e}));
}else{
// Not even once - write error directly into the HTML output so the user gets an error
// Maintain basic html structure to allow Livereloading scripts to be injected properly
file.contents = new Buffer('<!DOCTYPE html><html><head><title>Panini error</title></head><body><pre>'+e+'</pre></body></html>');
}
catch (e) {
if (layoutTemplate) {
// Layout was parsed properly so we can insert the error message into the body of the layout
this.Handlebars.registerPartial('body', 'Panini error: template could not be parsed <br> \n <pre>{{error}}</pre>');
file.contents = new Buffer(layoutTemplate({error:e}));
}
// log the error into console
else {
// Not even once - write error directly into the HTML output so the user gets an error
// Maintain basic html structure to allow Livereloading scripts to be injected properly
file.contents = new Buffer('<!DOCTYPE html><html><head><title>Panini error</title></head><body><pre>'+e+'</pre></body></html>');
}
// Log the error into console
console.log('Panini error: rendering error ocurred.\n',e);

} finally {
}
finally {
// This sends the modified file back into the stream
cb(null, file);
}
Expand Down

0 comments on commit c956e27

Please sign in to comment.