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

Merge pull request #6299 from acburdine/config-refactor

Refactor Config Service
This commit is contained in:
Hannah Wolfe 2016-01-25 13:22:20 +00:00
commit cf8abcb6be
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;