From 6437f343c1a27b2093c66c7b928820a1da3414e2 Mon Sep 17 00:00:00 2001 From: Joel Rosenberg Date: Mon, 13 Jan 2014 15:11:59 -0800 Subject: [PATCH] Including theme partials in a way that supports symbolically linked directories closes #1937 - using fs.stat() instead of hasOwnProperty() to test for directory existence --- core/server/middleware/index.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core/server/middleware/index.js b/core/server/middleware/index.js index 889f3248b8..6c773d50e8 100644 --- a/core/server/middleware/index.js +++ b/core/server/middleware/index.js @@ -10,6 +10,7 @@ var middleware = require('./middleware'), slashes = require('connect-slashes'), errors = require('../errorHandling'), api = require('../api'), + fs = require('fs'), path = require('path'), hbs = require('express-hbs'), config = require('../config'), @@ -91,6 +92,7 @@ function initViews(req, res, next) { // Helper for manageAdminAndTheme function activateTheme(activeTheme) { var hbsOptions, + themePartials = path.join(config.paths().themePath, activeTheme, 'partials'), stackLocation = _.indexOf(expressServer.stack, _.find(expressServer.stack, function (stackItem) { return stackItem.route === config.paths().subdir && stackItem.handle.name === 'settingEnabled'; })); @@ -106,10 +108,14 @@ function activateTheme(activeTheme) { // set view engine hbsOptions = { partialsDir: [ config.paths().helperTemplates ] }; - if (config.paths().availableThemes[activeTheme].hasOwnProperty('partials')) { + + fs.stat(themePartials, function (err, stats) { // Check that the theme has a partials directory before trying to use it - hbsOptions.partialsDir.push(path.join(config.paths().themePath, activeTheme, 'partials')); - } + if (!err && stats && stats.isDirectory()) { + hbsOptions.partialsDir.push(themePartials); + } + }); + expressServer.set('theme view engine', hbs.express3(hbsOptions)); // Update user error template