From eca82b66d4829abb0ad747d75e6b63fc3eba53df Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Thu, 24 Dec 2015 11:56:04 -0700 Subject: [PATCH] Better loading of themes & getAvailThemes() --- core/theme.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/core/theme.js b/core/theme.js index 8ada3fe1..ae6e1ca6 100644 --- a/core/theme.js +++ b/core/theme.js @@ -16,8 +16,10 @@ var async = require('async'); var _ = require('lodash'); var assert = require('assert'); + exports.loadTheme = loadTheme; exports.getThemeArt = getThemeArt; +exports.getAvailableThemes = getAvailableThemes; exports.getRandomTheme = getRandomTheme; exports.initAvailableThemes = initAvailableThemes; exports.displayThemeArt = displayThemeArt; @@ -72,7 +74,7 @@ function refreshThemeHelpers(theme) { return format; } - } + }; } function loadTheme(themeID, cb) { @@ -83,8 +85,11 @@ function loadTheme(themeID, cb) { if(err) { cb(err); } else { - if(!_.isObject(theme.info)) { - cb(new Error('Invalid theme or missing \'info\' section')); + if(!_.isObject(theme.info) || + !_.isString(theme.info.name) || + !_.isString(theme.info.author)) + { + cb(new Error('Invalid or missing "info" section!')); return; } @@ -128,6 +133,8 @@ function initAvailableThemes(cb) { }); Log.debug( { info : theme.info }, 'Theme loaded'); + } else { + Log.warn( { themeId : themeId, error : err.toString() }, 'Failed to load theme'); } }); @@ -146,6 +153,10 @@ function initAvailableThemes(cb) { ); } +function getAvailableThemes() { + return availableThemes; +} + function getRandomTheme() { if(Object.getOwnPropertyNames(availableThemes).length > 0) { var themeIds = Object.keys(availableThemes);