From 970b259e062515a99d7ba327e7fbb384a37ca3ef Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 1 May 2014 15:06:20 -0400 Subject: [PATCH] fixed #907 --- app.js | 1 - src/meta.js | 3 ++- src/middleware/index.js | 25 +++++++++++++++++-------- src/webserver.js | 6 +++--- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/app.js b/app.js index dd9f3b6d77..11cfb82d0b 100644 --- a/app.js +++ b/app.js @@ -135,7 +135,6 @@ function start() { nconf.set('url', nconf.get('base_url') + (nconf.get('use_port') ? ':' + nconf.get('port') : '') + nconf.get('relative_path')); nconf.set('base_templates_path', path.join(nconf.get('themes_path'), 'nodebb-theme-vanilla/templates')); - nconf.set('theme_templates_path', meta.config['theme:templates'] ? path.join(nconf.get('themes_path'), meta.config['theme:id'], meta.config['theme:templates']) : nconf.get('base_templates_path')); plugins.ready(function() { webserver.init(); diff --git a/src/meta.js b/src/meta.js index e52fd0ace1..4dfa3c1616 100644 --- a/src/meta.js +++ b/src/meta.js @@ -150,7 +150,7 @@ var fs = require('fs'), function(config, next) { themeData['theme:staticDir'] = config.staticDir ? config.staticDir : ''; themeData['theme:templates'] = config.templates ? config.templates : ''; - themeData['theme:src'] = config.frameworkCSS ? config.frameworkCSS : ''; + themeData['theme:src'] = ''; db.setObject('config', themeData, next); } @@ -234,6 +234,7 @@ var fs = require('fs'), 'vendor/jquery/js/jquery-ui-1.10.4.custom.js', 'vendor/jquery/timeago/jquery.timeago.min.js', 'vendor/jquery/js/jquery.form.min.js', + 'vendor/jquery/serializeObject/jquery.ba-serializeobject.min.js', 'vendor/bootstrap/js/bootstrap.min.js', 'vendor/requirejs/require.js', 'vendor/bootbox/bootbox.min.js', diff --git a/src/middleware/index.js b/src/middleware/index.js index a40bc0926e..1b42ab1f61 100644 --- a/src/middleware/index.js +++ b/src/middleware/index.js @@ -45,21 +45,31 @@ function routeThemeScreenshots(app, themes) { }); } -function routeCurrentTheme(app, themeData) { - var themeId = (themeData['theme:id'] || 'nodebb-theme-vanilla'); +function routeCurrentTheme(app, themeId, themesData) { + var themeId = (themeId || 'nodebb-theme-vanilla'), + themeObj = (function(id) { + return themesData.filter(function(themeObj) { + return themeObj.id === id; + })[0]; + })(themeId); // Detect if a theme has been selected, and handle appropriately if (process.env.NODE_ENV === 'development') { winston.info('[themes] Using theme ' + themeId); } - // Theme's static directory - if (themeData['theme:staticDir']) { - app.use(relativePath + '/css/assets', express.static(path.join(themesPath, themeData['theme:id'], themeData['theme:staticDir']), { + // Theme's templates path + nconf.set('theme_templates_path', themeObj.templates ? path.join(themesPath, themeObj.id, themeObj.templates) : nconf.get('base_templates_path')); + themeTemplatesPath = nconf.get('theme_templates_path'); + + // Theme's static directory (to be deprecated for 0.5.0) + if (themeObj.staticDir) { + app.use(relativePath + '/css/assets', express.static(path.join(themesPath, themeObj.id, themeObj.staticDir), { maxAge: app.enabled('cache') ? 5184000000 : 0 })); + if (process.env.NODE_ENV === 'development') { - winston.info('Static directory routed for theme: ' + themeData['theme:id']); + winston.info('Static directory routed for theme: ' + themeObj.id); } } } @@ -173,7 +183,6 @@ module.exports = function(app, data) { viewsPath = nconf.get('views_dir'); themesPath = nconf.get('themes_path'); baseTemplatesPath = nconf.get('base_templates_path'); - themeTemplatesPath = nconf.get('theme_templates_path'); app.configure(function() { app.engine('tpl', templates.__express); @@ -210,7 +219,7 @@ module.exports = function(app, data) { auth.initialize(app); - routeCurrentTheme(app, data.currentThemeData); + routeCurrentTheme(app, data.currentThemeId, data.themesData); routeThemeScreenshots(app, data.themesData); plugins.getTemplates(function(err, pluginTemplates) { diff --git a/src/webserver.js b/src/webserver.js index a9ffd958b6..efd42de0ec 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -49,10 +49,10 @@ if(nconf.get('ssl')) { meta.sounds.init(); }); - async.series({ + async.parallel({ themesData: meta.themes.get, - currentThemeData: function(next) { - db.getObjectFields('config', ['theme:type', 'theme:id', 'theme:staticDir', 'theme:templates'], next); + currentThemeId: function(next) { + db.getObjectField('config', 'theme:id', next); } }, function(err, data) { middleware = middleware(app, data);