Better loading of themes & getAvailThemes()

This commit is contained in:
Bryan Ashby 2015-12-24 11:56:04 -07:00
parent 37bba84cb4
commit eca82b66d4
1 changed files with 14 additions and 3 deletions

View File

@ -16,8 +16,10 @@ var async = require('async');
var _ = require('lodash'); var _ = require('lodash');
var assert = require('assert'); var assert = require('assert');
exports.loadTheme = loadTheme; exports.loadTheme = loadTheme;
exports.getThemeArt = getThemeArt; exports.getThemeArt = getThemeArt;
exports.getAvailableThemes = getAvailableThemes;
exports.getRandomTheme = getRandomTheme; exports.getRandomTheme = getRandomTheme;
exports.initAvailableThemes = initAvailableThemes; exports.initAvailableThemes = initAvailableThemes;
exports.displayThemeArt = displayThemeArt; exports.displayThemeArt = displayThemeArt;
@ -72,7 +74,7 @@ function refreshThemeHelpers(theme) {
return format; return format;
} }
} };
} }
function loadTheme(themeID, cb) { function loadTheme(themeID, cb) {
@ -83,8 +85,11 @@ function loadTheme(themeID, cb) {
if(err) { if(err) {
cb(err); cb(err);
} else { } else {
if(!_.isObject(theme.info)) { if(!_.isObject(theme.info) ||
cb(new Error('Invalid theme or missing \'info\' section')); !_.isString(theme.info.name) ||
!_.isString(theme.info.author))
{
cb(new Error('Invalid or missing "info" section!'));
return; return;
} }
@ -128,6 +133,8 @@ function initAvailableThemes(cb) {
}); });
Log.debug( { info : theme.info }, 'Theme loaded'); 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() { function getRandomTheme() {
if(Object.getOwnPropertyNames(availableThemes).length > 0) { if(Object.getOwnPropertyNames(availableThemes).length > 0) {
var themeIds = Object.keys(availableThemes); var themeIds = Object.keys(availableThemes);