Ghost/ghost/admin/app/services/config.js
Austin Burdine cf36851265 deps: grunt-jscs,ember-suave@3.0.0
replaces #41, #60
- update ember-suave and grunt-jscs to 3.0
- standardize Ember global de-structuring rules across app & tests
2016-06-11 13:39:31 -06:00

63 lines
1.5 KiB
JavaScript

import Ember from 'ember';
const {
$,
Service,
_ProxyMixin,
computed,
inject: {service}
} = Ember;
const {isNumeric} = $;
function _mapType(val, type) {
if (val === '') {
return null;
} else if (type === 'bool') {
return (val === 'true') ? true : false;
} else if (type === 'int' && isNumeric(val)) {
return +val;
} else if (type === 'json') {
try {
return JSON.parse(val);
} catch (e) {
return val;
}
} else { // assume string if type is null or matches nothing else
return val;
}
}
export default Service.extend(_ProxyMixin, {
ajax: service(),
ghostPaths: service(),
content: computed(function () {
let metaConfigTags = $('meta[name^="env-"]');
let config = {};
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, type);
});
return config;
}),
availableTimezones: computed(function() {
let timezonesUrl = this.get('ghostPaths.url').api('configuration', 'timezones');
return this.get('ajax').request(timezonesUrl).then((configTimezones) => {
let [ timezonesObj ] = configTimezones.configuration;
timezonesObj = timezonesObj.timezones;
return timezonesObj;
});
})
});