From 96688a8ffe1068807a67ef3043764420ed2edfcc Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 28 Aug 2013 16:32:59 -0400 Subject: [PATCH 1/3] changing method to retrieve themes to use /node_modules --- src/meta.js | 40 ++++++++++++++++++++-------------------- src/websockets.js | 1 + 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/meta.js b/src/meta.js index 9b0660b70b..5248a68d6b 100644 --- a/src/meta.js +++ b/src/meta.js @@ -42,31 +42,31 @@ var utils = require('./../public/src/utils.js'), Meta.themes = { get: function(callback) { - var themePath = path.join(__dirname, '../', 'public/themes'); + var themePath = path.join(__dirname, '../node_modules'); fs.readdir(themePath, function(err, files) { - var themeArr = []; - async.each(files, function(file, next) { - fs.lstat(path.join(themePath, file), function(err, stats) { - if(stats.isDirectory()) { - var themeDir = file, - themeConfPath = path.join(themePath, themeDir, 'theme.json'); + async.filter(files, function(file, next) { + fs.stat(path.join(themePath, file), function(err, fileStat) { + if (err) next(false); - fs.exists(themeConfPath, function(exists) { - if (exists) { - fs.readFile(themeConfPath, function(err, conf) { - conf = JSON.parse(conf); - conf.src = nconf.get('url') + 'themes/' + themeDir + '/' + conf.src; - if (conf.screenshot) conf.screenshot = nconf.get('url') + 'themes/' + themeDir + '/' + conf.screenshot; - else conf.screenshot = nconf.get('url') + 'images/themes/default.png'; - themeArr.push(conf); - next(); - }); - } else next(); + next((fileStat.isDirectory() && file.slice(0, 13) === 'nodebb-theme-')); + }); + }, function(themes) { + async.map(themes, function(theme, next) { + var config = path.join(themePath, theme, 'theme.json'); + + if (fs.existsSync(config)) { + fs.readFile(config, function(err, file) { + var configObj = JSON.parse(file.toString()); + if (!configObj.screenshot) configObj.screenshot = nconf.get('relative_path') + '/images/themes/default.png'; + next(err, configObj); }); } else next(); + }, function(err, themes) { + themes = themes.filter(function(theme) { + return (theme !== undefined); + }); + callback(null, themes); }); - }, function(err) { - callback(err, themeArr); }); }); } diff --git a/src/websockets.js b/src/websockets.js index c98ec013f5..77af926709 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -800,6 +800,7 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }), socket.on('api:admin.themes.getInstalled', function(callback) { meta.themes.get(function(err, themeArr) { + console.log(themeArr); callback(themeArr); }); }); From 13b456bffd78189449f1e2ac1c7effa8fdea9539 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 28 Aug 2013 21:33:17 -0400 Subject: [PATCH 2/3] fixing up bs3 integration for themes page --- public/src/forum/admin/themes.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/src/forum/admin/themes.js b/public/src/forum/admin/themes.js index 95881fec63..de6396715b 100644 --- a/public/src/forum/admin/themes.js +++ b/public/src/forum/admin/themes.js @@ -39,7 +39,7 @@ var nodebb_admin = (function(nodebb_admin) { (function() { var scriptEl = document.createElement('script'); - scriptEl.src = 'http://api.bootswatch.com/2/?callback=nodebb_admin.themes.render'; + scriptEl.src = 'http://api.bootswatch.com/3/?callback=nodebb_admin.themes.render'; document.body.appendChild(scriptEl); var bootstrapThemeContainer = document.querySelector('#bootstrap_themes'), @@ -94,7 +94,7 @@ var nodebb_admin = (function(nodebb_admin) { '
' + '
' + ' ' + - '' + + '' + '
' + '

' + themes[x].name + '

' + '

' + From 5ed7c312781046e79589f669f9a2926275a0e25b Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 28 Aug 2013 21:35:00 -0400 Subject: [PATCH 3/3] removing console logs --- src/websockets.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/websockets.js b/src/websockets.js index 7fbbad7b5f..f75eeda2a0 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -802,7 +802,6 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }), socket.on('api:admin.themes.getInstalled', function(callback) { meta.themes.get(function(err, themeArr) { - console.log(themeArr); callback(themeArr); }); });