From 05edfdc9c13fd244d85a0b286470793555d2bde1 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Fri, 10 Jan 2014 17:06:56 -0500 Subject: [PATCH 1/2] templates.js - if custom theme is missing a template, render default template --- public/src/templates.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/public/src/templates.js b/public/src/templates.js index 627aa50d51..7daaff75ed 100644 --- a/public/src/templates.js +++ b/public/src/templates.js @@ -62,12 +62,13 @@ function loadTemplates(templatesToLoad, customTemplateDir) { function loadServer() { - var loaded = templatesToLoad.length; + var loaded = templatesToLoad.length, + templatesPath = __dirname + '/../templates'; function getTemplates(directory) { for (var t in templatesToLoad) { (function (file) { - fs.readFile(directory + '/' + file + '.tpl', function (err, html) { + function loadFile(html) { var template = function () { this.toString = function () { return this.html; @@ -84,17 +85,27 @@ if (loaded === 0) { templates.ready(); } + } + + fs.readFile(directory + '/' + file + '.tpl', function (err, html) { + if (err && directory !== templatesPath) { + fs.readFile(templatesPath + '/' + file + '.tpl', function (err, html) { + loadFile(html); + }); + } else { + loadFile(html); + } }); }(templatesToLoad[t])); } } if (customTemplateDir) { fs.exists(customTemplateDir, function (exists) { - var directory = (exists ? customTemplateDir : __dirname + '/../templates'); + var directory = (exists ? customTemplateDir : templatesPath); getTemplates(directory); }); } else { - getTemplates(__dirname + '/../templates'); + getTemplates(templatesPath); } } @@ -113,6 +124,7 @@ templates.init = function (templates_to_load, custom_templates) { + console.log(templates_to_load, custom_templates); loadTemplates(templates_to_load || [], custom_templates || false); } From 97ec312c721a18369ebe79885e67f8562fa21561 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Fri, 10 Jan 2014 17:08:01 -0500 Subject: [PATCH 2/2] console.log --- public/src/templates.js | 1 - 1 file changed, 1 deletion(-) diff --git a/public/src/templates.js b/public/src/templates.js index 7daaff75ed..538bd6b8ac 100644 --- a/public/src/templates.js +++ b/public/src/templates.js @@ -124,7 +124,6 @@ templates.init = function (templates_to_load, custom_templates) { - console.log(templates_to_load, custom_templates); loadTemplates(templates_to_load || [], custom_templates || false); }