diff --git a/Gruntfile.js b/Gruntfile.js index d2a24ee254..3090606d4a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -835,7 +835,7 @@ var _ = require('lodash'), // // `NODE_ENV=testing mocha --timeout=15000 --ui=bdd --reporter=spec core/test/unit/config_spec.js` // - // Unit tests are run with [mocha](http://visionmedia.github.io/mocha/) using + // Unit tests are run with [mocha](http://mochajs.org/) using // [should](https://github.com/visionmedia/should.js) to describe the tests in a highly readable style. // Unit tests do **not** touch the database. // A coverage report can be generated for these tests using the `grunt test-coverage` task. @@ -853,7 +853,7 @@ var _ = require('lodash'), // // `NODE_ENV=testing grunt mochacli:api` // - // Integration tests are run with [mocha](http://visionmedia.github.io/mocha/) using + // Integration tests are run with [mocha](http://mochajs.org/) using // [should](https://github.com/visionmedia/should.js) to describe the tests in a highly readable style. // Integration tests are different to the unit tests because they make requests to the database. // @@ -879,7 +879,7 @@ var _ = require('lodash'), // // `NODE_ENV=testing mocha --timeout=15000 --ui=bdd --reporter=spec core/test/functional/routes/admin_test.js` // - // Route tests are run with [mocha](http://visionmedia.github.io/mocha/) using + // Route tests are run with [mocha](http://mochajs.org/) using // [should](https://github.com/visionmedia/should.js) and [supertest](https://github.com/visionmedia/supertest) // to describe and create the tests. // diff --git a/core/client/initializers/ghost-config.js b/core/client/initializers/ghost-config.js index 519d900306..244f14fe7a 100644 --- a/core/client/initializers/ghost-config.js +++ b/core/client/initializers/ghost-config.js @@ -1,16 +1,11 @@ +import getConfig from 'ghost/utils/config-parser'; + var ConfigInitializer = { name: 'config', initialize: function (container, application) { - var apps = $('body').data('apps'), - tagsUI = $('body').data('tagsui'), - fileStorage = $('body').data('filestorage'), - blogUrl = $('body').data('blogurl'), - blogTitle = $('body').data('blogtitle'); - - application.register( - 'ghost:config', {apps: apps, fileStorage: fileStorage, blogUrl: blogUrl, tagsUI: tagsUI, blogTitle: blogTitle}, {instantiate: false} - ); + var config = getConfig(); + application.register('ghost:config', config, {instantiate: false}); application.inject('route', 'config', 'ghost:config'); application.inject('controller', 'config', 'ghost:config'); diff --git a/core/client/utils/config-parser.js b/core/client/utils/config-parser.js new file mode 100644 index 0000000000..7082fa04f9 --- /dev/null +++ b/core/client/utils/config-parser.js @@ -0,0 +1,36 @@ +var isNumeric = function (num) { + return !isNaN(num); + }, + + _mapType = function (val) { + if (val === '') { + return null; + } else if (val === 'true') { + return true; + } else if (val === 'false') { + return false; + } else if (isNumeric(val)) { + return +val; + } else { + return val; + } + }, + + parseConfiguration = function () { + var metaConfigTags = $('meta[name^="env-"]'), + propertyName, + config = {}, + value, + key, + i; + + for (i = 0; i < metaConfigTags.length; i += 1) { + key = $(metaConfigTags[i]).prop('name'); + value = $(metaConfigTags[i]).prop('content'); + propertyName = key.substring(4); // produce config name ignoring the initial 'env-'. + config[propertyName] = _mapType(value); // map string values to types if possible + } + return config; + }; + +export default parseConfiguration; diff --git a/core/server/api/configuration.js b/core/server/api/configuration.js index 74b88d9113..2faaae4d1f 100644 --- a/core/server/api/configuration.js +++ b/core/server/api/configuration.js @@ -17,7 +17,8 @@ function getValidKeys() { environment: process.env.NODE_ENV, database: config.database.client, mail: _.isObject(config.mail) ? config.mail.transport : '', - blogUrl: config.url + blogUrl: config.url, + blogTitle: config.theme.title }; return parsePackageJson('package.json').then(function (json) { diff --git a/core/server/controllers/admin.js b/core/server/controllers/admin.js index 2196fdcc25..ee44be65c7 100644 --- a/core/server/controllers/admin.js +++ b/core/server/controllers/admin.js @@ -13,8 +13,15 @@ adminControllers = { /*jslint unparam:true*/ function renderIndex() { - res.render('default', { - skip_google_fonts: config.isPrivacyDisabled('useGoogleFonts') + return api.configuration.browse().then(function (data) { + var apiConfig = _.omit(data.configuration, function (value) { + return _.contains(['environment', 'database', 'mail', 'version'], value.key); + }); + + res.render('default', { + skip_google_fonts: config.isPrivacyDisabled('useGoogleFonts'), + configuration: apiConfig + }); }); } diff --git a/core/server/helpers/index.js b/core/server/helpers/index.js index e7d6ee39f3..3f560d29df 100644 --- a/core/server/helpers/index.js +++ b/core/server/helpers/index.js @@ -1,12 +1,7 @@ var hbs = require('express-hbs'), - _ = require('lodash'), Promise = require('bluebird'), - - config = require('../config'), errors = require('../errors'), - utils = require('./utils'), - coreHelpers = {}, registerHelpers; @@ -44,70 +39,6 @@ coreHelpers.image = require('./image'); coreHelpers.ghost_script_tags = require('./ghost_script_tags'); -// ### Filestorage helper -// -// *Usage example:* -// `{{file_storage}}` -// -// Returns the config value for fileStorage. -coreHelpers.file_storage = function (context, options) { - /*jshint unused:false*/ - if (config.hasOwnProperty('fileStorage')) { - return _.isObject(config.fileStorage) ? 'true' : config.fileStorage.toString(); - } - return 'true'; -}; - -// ### Apps helper -// -// *Usage example:* -// `{{apps}}` -// -// Returns the config value for apps. -coreHelpers.apps = function (context, options) { - /*jshint unused:false*/ - if (config.hasOwnProperty('apps')) { - return config.apps.toString(); - } - return 'false'; -}; - -// ### TagsUI helper -// -// *Usage example:* -// `{{tags_ui}}` -// -// Returns the config value for tagsUI or false if no value present -coreHelpers.tags_ui = function (context, options) { - /*jshint unused:false*/ - if (config.hasOwnProperty('tagsUI')) { - return config.tagsUI.toString(); - } - return 'false'; -}; - -// ### Blog Url helper -// -// *Usage example:* -// `{{blog_url}}` -// -// Returns the config value for url. -coreHelpers.blog_url = function (context, options) { - /*jshint unused:false*/ - return config.theme.url.toString(); -}; - -// ### Blog Title helper -// -// *Usage example:* -// `{{blog_title}}` -// -// Returns the config value for url. -coreHelpers.blog_title = function (context, options) { - /*jshint unused:false*/ - return config.theme.title.toString(); -}; - coreHelpers.helperMissing = function (arg) { if (arguments.length === 2) { return undefined; @@ -177,12 +108,6 @@ registerHelpers = function (adminHbs) { // Register admin helpers registerAdminHelper('ghost_script_tags', coreHelpers.ghost_script_tags); registerAdminHelper('asset', coreHelpers.asset); - registerAdminHelper('apps', coreHelpers.apps); - registerAdminHelper('file_storage', coreHelpers.file_storage); - registerAdminHelper('tags_ui', coreHelpers.tags_ui); - - registerAdminHelper('blog_title', coreHelpers.blog_title); - registerAdminHelper('blog_url', coreHelpers.blog_url); }; module.exports = coreHelpers; diff --git a/core/server/views/default.hbs b/core/server/views/default.hbs index ebcfbc40ad..3af77c74c1 100644 --- a/core/server/views/default.hbs +++ b/core/server/views/default.hbs @@ -29,14 +29,18 @@ + {{#each configuration}} + + {{/each}} + {{#unless skip_google_fonts}} {{/unless}} - + {{{ghost_script_tags}}} - \ No newline at end of file + diff --git a/core/test/unit/server_helpers_index_spec.js b/core/test/unit/server_helpers_index_spec.js index cf3c079dd8..ab5c5803d9 100644 --- a/core/test/unit/server_helpers_index_spec.js +++ b/core/test/unit/server_helpers_index_spec.js @@ -1,33 +1,18 @@ -/*globals describe, beforeEach, afterEach, it*/ +/*globals describe, beforeEach, it*/ /*jshint expr:true*/ +// jscs:disable requireCamelCaseOrUpperCaseIdentifiers var should = require('should'), - _ = require('lodash'), rewire = require('rewire'), hbs = require('express-hbs'), // Stuff we are testing - helpers = rewire('../../server/helpers'), - config = rewire('../../server/config'); + + helpers = rewire('../../server/helpers'); describe('Helpers', function () { - var overrideConfig = function (newConfig) { - var existingConfig = helpers.__get__('config'); - config.set(_.extend(existingConfig, newConfig)); - }; - beforeEach(function () { var adminHbs = hbs.create(); helpers = rewire('../../server/helpers'); - - overrideConfig({ - paths: { - subdir: '' - }, - theme: { - url: 'http://testurl.com' - } - }); - helpers.loadCoreHelpers(adminHbs); }); @@ -48,95 +33,4 @@ describe('Helpers', function () { runHelper('test helper', 'second argument').should.not.throwError(); }); }); - - describe('file storage helper', function () { - it('is loaded', function () { - should.exist(helpers.file_storage); - }); - - it('should return the string true when config() has no fileStorage property', function () { - var fileStorage = helpers.file_storage(); - - should.exist(fileStorage); - fileStorage.should.equal('true'); - }); - - it('should return the config.fileStorage value when it exists', function () { - var setting = 'file storage value', - cfg = helpers.__get__('config'), - fileStorage; - - _.extend(cfg, { - fileStorage: setting - }); - - fileStorage = helpers.file_storage(); - - should.exist(fileStorage); - fileStorage.should.equal(setting); - }); - - it('should just return true if config.fileStorage is an object', function () { - var setting = {someKey: 'someValue'}, - cfg = helpers.__get__('config'), - fileStorage; - - _.extend(cfg, { - fileStorage: setting - }); - - fileStorage = helpers.file_storage(); - - should.exist(fileStorage); - fileStorage.should.equal('true'); - }); - }); - - describe('apps helper', function () { - it('is loaded', function () { - should.exist(helpers.apps); - }); - - it('should return the string false when config() has no apps property', function () { - var apps = helpers.apps(); - - should.exist(apps); - apps.should.equal('false'); - }); - - it('should return the config.apps value when it exists', function () { - var setting = 'app value', - cfg = helpers.__get__('config'), - apps; - - _.extend(cfg, { - apps: setting - }); - - apps = helpers.apps(); - - should.exist(apps); - apps.should.equal(setting); - }); - }); - - describe('blog_url helper', function () { - var configUrl = config.url; - - afterEach(function () { - config.set({url: configUrl}); - }); - - it('is loaded', function () { - should.exist(helpers.blog_url); - }); - - it('should return the test url by default', function () { - var blogUrl = helpers.blog_url(); - - should.exist(blogUrl); - // this is set in another test == bad! - blogUrl.should.equal('http://testurl.com'); - }); - }); });