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:
commit
cf8abcb6be
2 changed files with 10 additions and 11 deletions
|
@ -32,7 +32,7 @@
|
||||||
<meta name="msapplication-square310x310logo" content="{{asset "img/large.png" ghost="true"}}" />
|
<meta name="msapplication-square310x310logo" content="{{asset "img/large.png" ghost="true"}}" />
|
||||||
|
|
||||||
{{#each configuration}}
|
{{#each configuration}}
|
||||||
<meta name="env-{{this.key}}" content="{{this.value}}" />
|
<meta name="env-{{this.key}}" content="{{this.value}}" data-type="{{this.type}}" />
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
||||||
{{#unless skip_google_fonts}}
|
{{#unless skip_google_fonts}}
|
||||||
|
|
|
@ -6,23 +6,20 @@ function isNumeric(num) {
|
||||||
return Ember.$.isNumeric(num);
|
return Ember.$.isNumeric(num);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _mapType(val) {
|
function _mapType(val, type) {
|
||||||
if (val === '') {
|
if (val === '') {
|
||||||
return null;
|
return null;
|
||||||
} else if (val === 'true') {
|
} else if (type === 'bool') {
|
||||||
return true;
|
return (val === 'true') ? true : false;
|
||||||
} else if (val === 'false') {
|
} else if (type === 'int' && isNumeric(val)) {
|
||||||
return false;
|
|
||||||
} else if (isNumeric(val)) {
|
|
||||||
return +val;
|
return +val;
|
||||||
} else if (val.indexOf('{') === 0) {
|
} else if (type === 'json') {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(val);
|
return JSON.parse(val);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
/*jshint unused:false */
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
} else {
|
} else { // assume string if type is null or matches nothing else
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,9 +32,11 @@ export default Service.extend(_ProxyMixin, {
|
||||||
metaConfigTags.each((i, el) => {
|
metaConfigTags.each((i, el) => {
|
||||||
let key = el.name;
|
let key = el.name;
|
||||||
let value = el.content;
|
let value = el.content;
|
||||||
|
let type = el.getAttribute('data-type');
|
||||||
|
|
||||||
let propertyName = key.substring(4);
|
let propertyName = key.substring(4);
|
||||||
|
|
||||||
config[propertyName] = _mapType(value);
|
config[propertyName] = _mapType(value, type);
|
||||||
});
|
});
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
|
|
Loading…
Add table
Reference in a new issue