2015-05-26 05:10:50 +03:00
|
|
|
import Ember from 'ember';
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
const {Service, _ProxyMixin, computed} = Ember;
|
|
|
|
|
2015-05-26 05:10:50 +03:00
|
|
|
function isNumeric(num) {
|
2015-09-09 16:19:45 +03:00
|
|
|
return Ember.$.isNumeric(num);
|
2015-05-26 05:10:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
export default Service.extend(_ProxyMixin, {
|
|
|
|
content: computed(function () {
|
|
|
|
let metaConfigTags = Ember.$('meta[name^="env-"]');
|
|
|
|
let config = {};
|
2015-05-26 05:10:50 +03:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
metaConfigTags.each((i, el) => {
|
|
|
|
let key = el.name;
|
|
|
|
let value = el.content;
|
|
|
|
let propertyName = key.substring(4);
|
2015-05-26 05:10:50 +03:00
|
|
|
|
|
|
|
config[propertyName] = _mapType(value);
|
|
|
|
});
|
|
|
|
|
|
|
|
return config;
|
|
|
|
})
|
|
|
|
});
|