diff --git a/core/frontend/services/themes/Storage.js b/core/frontend/services/themes/ThemeStorage.js similarity index 100% rename from core/frontend/services/themes/Storage.js rename to core/frontend/services/themes/ThemeStorage.js diff --git a/core/frontend/services/themes/index.js b/core/frontend/services/themes/index.js index 47fc40d657..66b4880f29 100644 --- a/core/frontend/services/themes/index.js +++ b/core/frontend/services/themes/index.js @@ -5,14 +5,10 @@ const themeLoader = require('./loader'); const active = require('./active'); const activate = require('./activate'); const validate = require('./validate'); -const Storage = require('./Storage'); +const list = require('./list'); const settingsCache = require('../../../server/services/settings/cache'); const engineDefaults = require('./engines/defaults'); -let themeStorage; - -// @TODO: reduce the amount of things we expose to the outside world -// Make this a nice clean sensible API we can all understand! module.exports = { // Init themes module // TODO: move this once we're clear what needs to happen here @@ -78,17 +74,7 @@ module.exports = { common.logging.error(err); }); }, - // Load themes, soon to be removed and exposed via specific function. - loadAll: themeLoader.loadAllThemes, - loadOne: themeLoader.loadOneTheme, - get storage() { - themeStorage = themeStorage || new Storage(); - - return themeStorage; - }, - list: require('./list'), - validate: validate, - toJSON: require('./to-json'), + getJSON: require('./to-json'), getActive: active.get, getApiVersion: function getApiVersion() { if (this.getActive()) { @@ -98,7 +84,7 @@ module.exports = { } }, activate: function (themeName) { - const loadedTheme = this.list.get(themeName); + const loadedTheme = list.get(themeName); if (!loadedTheme) { return Promise.reject(new common.errors.ValidationError({ @@ -115,6 +101,6 @@ module.exports = { return checkedTheme; }); }, - settings: require('./settings'), + storage: require('./storage'), middleware: require('./middleware') }; diff --git a/core/frontend/services/themes/settings.js b/core/frontend/services/themes/storage.js similarity index 97% rename from core/frontend/services/themes/settings.js rename to core/frontend/services/themes/storage.js index 5105ea319f..d21cac25b3 100644 --- a/core/frontend/services/themes/settings.js +++ b/core/frontend/services/themes/storage.js @@ -3,7 +3,7 @@ const fs = require('fs-extra'); const activate = require('./activate'); const validate = require('./validate'); const list = require('./list'); -const Storage = require('./Storage'); +const ThemeStorage = require('./ThemeStorage'); const themeLoader = require('./loader'); const toJSON = require('./to-json'); @@ -14,13 +14,12 @@ const debug = require('ghost-ignition').debug('api:themes'); let themeStorage; const getStorage = () => { - themeStorage = themeStorage || new Storage(); + themeStorage = themeStorage || new ThemeStorage(); return themeStorage; }; module.exports = { - get: require('./to-json'), getZip: (themeName) => { const theme = list.get(themeName); diff --git a/core/server/api/v0.1/themes.js b/core/server/api/v0.1/themes.js index 248618131c..293ac83184 100644 --- a/core/server/api/v0.1/themes.js +++ b/core/server/api/v0.1/themes.js @@ -26,7 +26,7 @@ themes = { // Main action .then(() => { // Return JSON result - return themeService.settings.get(); + return themeService.getJSON(); }); }, @@ -52,7 +52,7 @@ themes = { }) .then((checkedTheme) => { // Return JSON result - return themeService.settings.get(themeName, checkedTheme); + return themeService.getJSON(themeName, checkedTheme); }); }, @@ -72,7 +72,7 @@ themes = { .handlePermissions('themes', 'add')(options) // Validation .then(() => { - return themeService.settings.setFromZip(zip); + return themeService.storage.setFromZip(zip); }) .then((theme) => { common.events.emit('theme.uploaded'); @@ -87,7 +87,7 @@ themes = { // Permissions .handlePermissions('themes', 'read')(options) .then(() => { - return themeService.settings.getZip(themeName); + return themeService.storage.getZip(themeName); }); }, @@ -103,7 +103,7 @@ themes = { .handlePermissions('themes', 'destroy')(options) // Validation .then(() => { - return themeService.settings.destroy(themeName); + return themeService.storage.destroy(themeName); }); } }; diff --git a/core/server/api/v2/themes.js b/core/server/api/v2/themes.js index 4821da73e0..19b16ea1dc 100644 --- a/core/server/api/v2/themes.js +++ b/core/server/api/v2/themes.js @@ -8,7 +8,7 @@ module.exports = { browse: { permissions: true, query() { - return themeService.settings.get(); + return themeService.getJSON(); } }, @@ -41,7 +41,7 @@ module.exports = { .then(() => checkedTheme); }) .then((checkedTheme) => { - return themeService.settings.get(themeName, checkedTheme); + return themeService.getJSON(themeName, checkedTheme); }); } }, @@ -60,7 +60,7 @@ module.exports = { name: frame.file.originalname }; - return themeService.settings.setFromZip(zip) + return themeService.storage.setFromZip(zip) .then((theme) => { common.events.emit('theme.uploaded'); return theme; @@ -85,7 +85,7 @@ module.exports = { query(frame) { let themeName = frame.options.name; - return themeService.settings.getZip(themeName); + return themeService.storage.getZip(themeName); } }, @@ -108,7 +108,7 @@ module.exports = { query(frame) { let themeName = frame.options.name; - return themeService.settings.destroy(themeName); + return themeService.storage.destroy(themeName); } } }; diff --git a/core/test/unit/helpers/body_class_spec.js b/core/test/unit/helpers/body_class_spec.js index 0f2412892f..29bf41d86b 100644 --- a/core/test/unit/helpers/body_class_spec.js +++ b/core/test/unit/helpers/body_class_spec.js @@ -1,5 +1,5 @@ var should = require('should'), - themeList = require('../../../frontend/services/themes').list, + themeList = require('../../../frontend/services/themes/list'), // Stuff we are testing helpers = require('../../../frontend/helpers'); diff --git a/core/test/unit/services/themes/list_spec.js b/core/test/unit/services/themes/list_spec.js index f15c9958ce..ef7283a0fc 100644 --- a/core/test/unit/services/themes/list_spec.js +++ b/core/test/unit/services/themes/list_spec.js @@ -1,8 +1,7 @@ var should = require('should'), sinon = require('sinon'), _ = require('lodash'), - themes = require('../../../../frontend/services/themes'), - themeList = themes.list; + themeList = require('../../../../frontend/services/themes/list'); describe('Themes', function () { afterEach(function () { diff --git a/core/test/unit/services/themes/loader_spec.js b/core/test/unit/services/themes/loader_spec.js index 3972122daa..19471e1f82 100644 --- a/core/test/unit/services/themes/loader_spec.js +++ b/core/test/unit/services/themes/loader_spec.js @@ -4,8 +4,8 @@ var should = require('should'), tmp = require('tmp'), join = require('path').join, config = require('../../../../server/config'), - themes = require('../../../../frontend/services/themes'), - themeList = themes.list; + loader = require('../../../../frontend/services/themes/loader'), + themeList = require('../../../../frontend/services/themes/list'); describe('Themes', function () { afterEach(function () { @@ -36,7 +36,7 @@ describe('Themes', function () { fs.writeFileSync(join(themePath.name, 'casper', 'index.hbs')); fs.writeFileSync(join(themePath.name, 'casper', 'partials', 'navigation.hbs')); - themes.loadAll() + loader.loadAllThemes() .then(function (result) { var themeResult = themeList.getAll(); @@ -69,7 +69,7 @@ describe('Themes', function () { JSON.stringify({name: 'casper', version: '0.1.2'}) ); - themes.loadAll() + loader.loadAllThemes() .then(function (result) { var themeResult = themeList.getAll(); @@ -111,7 +111,7 @@ describe('Themes', function () { fs.mkdirSync(join(themePath.name, 'not-casper')); fs.writeFileSync(join(themePath.name, 'not-casper', 'index.hbs')); - themes.loadOne('casper') + loader.loadOneTheme('casper') .then(function (themeResult) { themeResult.should.eql({ name: 'casper', @@ -129,7 +129,7 @@ describe('Themes', function () { fs.writeFileSync(join(themePath.name, 'casper.zip')); fs.writeFileSync(join(themePath.name, '.DS_Store')); - themes.loadOne('casper') + loader.loadOneTheme('casper') .then(function () { done('Should have thrown an error'); }) diff --git a/core/test/unit/services/themes/validate_spec.js b/core/test/unit/services/themes/validate_spec.js index 511e2a7f0c..c1fbbedc64 100644 --- a/core/test/unit/services/themes/validate_spec.js +++ b/core/test/unit/services/themes/validate_spec.js @@ -2,8 +2,7 @@ const should = require('should'); const sinon = require('sinon'); const _ = require('lodash'); -const themes = require('../../../../frontend/services/themes'); -const validate = themes.validate; +const validate = require('../../../../frontend/services/themes/validate'); const gscan = require('gscan');