2015-05-25 21:10:50 -05:00
|
|
|
import Ember from 'ember';
|
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
const {Service, _ProxyMixin, computed} = Ember;
|
|
|
|
|
2015-05-25 21:10:50 -05:00
|
|
|
function isNumeric(num) {
|
2015-09-09 08:19:45 -05:00
|
|
|
return Ember.$.isNumeric(num);
|
2015-05-25 21:10:50 -05:00
|
|
|
}
|
|
|
|
|
2016-01-19 09:43:09 -06:00
|
|
|
function _mapType(val, type) {
|
2015-05-25 21:10:50 -05:00
|
|
|
if (val === '') {
|
|
|
|
return null;
|
2016-01-19 09:43:09 -06:00
|
|
|
} else if (type === 'bool') {
|
|
|
|
return (val === 'true') ? true : false;
|
|
|
|
} else if (type === 'int' && isNumeric(val)) {
|
2015-05-25 21:10:50 -05:00
|
|
|
return +val;
|
2016-01-19 09:43:09 -06:00
|
|
|
} else if (type === 'json') {
|
2015-05-25 21:10:50 -05:00
|
|
|
try {
|
|
|
|
return JSON.parse(val);
|
|
|
|
} catch (e) {
|
|
|
|
return val;
|
|
|
|
}
|
2016-01-19 09:43:09 -06:00
|
|
|
} else { // assume string if type is null or matches nothing else
|
2015-05-25 21:10:50 -05:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
export default Service.extend(_ProxyMixin, {
|
|
|
|
content: computed(function () {
|
|
|
|
let metaConfigTags = Ember.$('meta[name^="env-"]');
|
|
|
|
let config = {};
|
2015-05-25 21:10:50 -05:00
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
metaConfigTags.each((i, el) => {
|
|
|
|
let key = el.name;
|
|
|
|
let value = el.content;
|
2016-01-19 09:43:09 -06:00
|
|
|
let type = el.getAttribute('data-type');
|
|
|
|
|
2015-10-28 11:36:45 +00:00
|
|
|
let propertyName = key.substring(4);
|
2015-05-25 21:10:50 -05:00
|
|
|
|
2016-01-19 09:43:09 -06:00
|
|
|
config[propertyName] = _mapType(value, type);
|
2015-05-25 21:10:50 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
return config;
|
|
|
|
})
|
|
|
|
});
|