From b72667698306423c571db79dffb906875a9192a2 Mon Sep 17 00:00:00 2001 From: Austin Burdine Date: Tue, 19 Jan 2016 09:43:09 -0600 Subject: [PATCH] refactor admin config to include explicit value types closes #6266 - add "type" to valid keys in configuration api - refactor ember config service to parse values based on provided type --- ghost/admin/app/index.html | 2 +- ghost/admin/app/services/config.js | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/ghost/admin/app/index.html b/ghost/admin/app/index.html index e194d1b5dc..1b3d24e432 100644 --- a/ghost/admin/app/index.html +++ b/ghost/admin/app/index.html @@ -32,7 +32,7 @@ {{#each configuration}} - + {{/each}} {{#unless skip_google_fonts}} diff --git a/ghost/admin/app/services/config.js b/ghost/admin/app/services/config.js index e4f7fcd514..b71b3bc2d8 100644 --- a/ghost/admin/app/services/config.js +++ b/ghost/admin/app/services/config.js @@ -6,23 +6,20 @@ function isNumeric(num) { return Ember.$.isNumeric(num); } -function _mapType(val) { +function _mapType(val, type) { if (val === '') { return null; - } else if (val === 'true') { - return true; - } else if (val === 'false') { - return false; - } else if (isNumeric(val)) { + } else if (type === 'bool') { + return (val === 'true') ? true : false; + } else if (type === 'int' && isNumeric(val)) { return +val; - } else if (val.indexOf('{') === 0) { + } else if (type === 'json') { try { return JSON.parse(val); } catch (e) { - /*jshint unused:false */ return val; } - } else { + } else { // assume string if type is null or matches nothing else return val; } } @@ -35,9 +32,11 @@ export default Service.extend(_ProxyMixin, { metaConfigTags.each((i, el) => { let key = el.name; let value = el.content; + let type = el.getAttribute('data-type'); + let propertyName = key.substring(4); - config[propertyName] = _mapType(value); + config[propertyName] = _mapType(value, type); }); return config;