0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

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
This commit is contained in:
Austin Burdine 2016-01-19 09:43:09 -06:00
parent 3154dfe988
commit b726676983
2 changed files with 10 additions and 11 deletions

View file

@ -32,7 +32,7 @@
<meta name="msapplication-square310x310logo" content="{{asset "img/large.png" ghost="true"}}" />
{{#each configuration}}
<meta name="env-{{this.key}}" content="{{this.value}}" />
<meta name="env-{{this.key}}" content="{{this.value}}" data-type="{{this.type}}" />
{{/each}}
{{#unless skip_google_fonts}}

View file

@ -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;