Ghost/core/server/themes/to-json.js
Hannah Wolfe 3996b5debb 🐷 💄 Tiny theme-related improvements (#8532)
refs #8530

- display theme name for non-fatal errors
- minor wording tweak
- remove duplicate lodash require
- use the shiny new calculated property syntax
2017-06-06 13:33:18 +02:00

39 lines
1.2 KiB
JavaScript

var _ = require('lodash'),
themeList = require('./list'),
packages = require('../utils/packages'),
settingsCache = require('../settings/cache');
/**
* Provides a JSON object which can be returned via the API
*
* @param {string} [name] - the theme to output
* @param {object} [checkedTheme] - a theme result from gscan
* @return {*}
*/
module.exports = function toJSON(name, checkedTheme) {
var themeResult, toFilter;
if (!name) {
toFilter = themeList.getAll();
// Default to returning the full list
themeResult = packages.filterPackages(toFilter, settingsCache.get('active_theme'));
} else {
// If we pass in a gscan result, convert this instead
toFilter = {
[name]: themeList.get(name)
};
themeResult = packages.filterPackages(toFilter, settingsCache.get('active_theme'));
if (checkedTheme && checkedTheme.results.warning.length > 0) {
themeResult[0].warnings = _.cloneDeep(checkedTheme.results.warning);
}
if (checkedTheme && checkedTheme.results.error.length > 0) {
themeResult[0].errors = _.cloneDeep(checkedTheme.results.error);
}
}
return {themes: themeResult};
};