From c86d174be40a3b8afe3a6cda096a7592c5038035 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jakub=20Sko=C5=99epa?= <jakub@skorepa.info>
Date: Tue, 22 Mar 2016 18:10:13 +0100
Subject: [PATCH] Fix crash with wrong template

+ add log filter for use in templates
---
 sitegin/nunjucks.js | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/sitegin/nunjucks.js b/sitegin/nunjucks.js
index 7534dffe..328d4adc 100644
--- a/sitegin/nunjucks.js
+++ b/sitegin/nunjucks.js
@@ -36,7 +36,11 @@ env.addFilter('paginationList', function(page, count) {
 });
 
 env.addFilter('inspect', function(obj) {
-    return util.inspect(obj);
+  return util.inspect(obj);
+});
+
+env.addFilter('log', function(obj) {
+  return console.log(obj);
 });
 
 env.addFilter('relURL', function(filename, dir){
@@ -53,6 +57,13 @@ module.exports = function(data, type) {
       resolve(tmpl);
     });
   }).then(function(tmpl) {
-    return tmpl.render(data);
+    return new Promise(function(resolve, reject){
+      tmpl.render(data, function(err, val) {
+        if(err) {
+          reject(err);
+        }
+        resolve(val);
+      });
+    })
   });
 }
-- 
GitLab