0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00
ghost/core/client/app/services/config.js
Kevin Ansfield 3d6856614f Use es6 across client and add ember-suave to enforce rules
no issue
- add ember-suave dependency
- upgrade grunt-jscs dependency
- add a new .jscsrc for the client's tests directory that extends from client's base .jscsrc
- separate client tests in Gruntfile jscs task so they pick up the test's .jscsrc
- standardize es6 usage across client
2015-11-30 10:41:01 +00:00

45 lines
1,023 B
JavaScript

import Ember from 'ember';
const {Service, _ProxyMixin, computed} = Ember;
function isNumeric(num) {
return Ember.$.isNumeric(num);
}
function _mapType(val) {
if (val === '') {
return null;
} else if (val === 'true') {
return true;
} else if (val === 'false') {
return false;
} else if (isNumeric(val)) {
return +val;
} else if (val.indexOf('{') === 0) {
try {
return JSON.parse(val);
} catch (e) {
/*jshint unused:false */
return val;
}
} else {
return val;
}
}
export default Service.extend(_ProxyMixin, {
content: computed(function () {
let metaConfigTags = Ember.$('meta[name^="env-"]');
let config = {};
metaConfigTags.each((i, el) => {
let key = el.name;
let value = el.content;
let propertyName = key.substring(4);
config[propertyName] = _mapType(value);
});
return config;
})
});