28
|
1 |
// Copied and modified from https://gist.github.com/walter/3e852e8ebc87535a3c91 |
|
2 |
import Ember from 'ember'; |
|
3 |
import config from 'bo-client/config/environment'; |
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
export function initialize(application) { |
|
8 |
var OptionsReader = function OptionsReader() { |
|
9 |
this.readOptionsKeys = function() { |
|
10 |
var _mapType = function(val) { |
|
11 |
return "" === val ? null : "true" === val ? true : "false" === val ? false : (-1 !== val.indexOf(",") && (val = val.split(",")), val); |
|
12 |
}; |
|
13 |
|
|
14 |
// Grab all the meta tags from the DOM. |
|
15 |
var metaTags = Ember.$("meta"); |
|
16 |
var options = Ember.Object.create(); |
|
17 |
var re = new RegExp(config.modulePrefix + '\.'); |
|
18 |
|
|
19 |
// Process each of the discovered meta tags. |
|
20 |
for(var i=0; i < metaTags.length; i++) { |
|
21 |
var key = Ember.$(metaTags[i]).attr('name'); |
|
22 |
var value = Ember.$(metaTags[i]).attr('content'); |
|
23 |
|
|
24 |
// Does the meta tag start with our MODULE_PREFIX? |
|
25 |
if (re.test(key)) { |
|
26 |
var propertyName = Ember.String.camelize(key.substring(config.modulePrefix.length+1)); |
|
27 |
options[propertyName] = _mapType(value); |
|
28 |
} |
|
29 |
} |
|
30 |
return options; |
|
31 |
}; |
|
32 |
}; |
|
33 |
|
|
34 |
var optionsReader = new OptionsReader(); |
|
35 |
|
|
36 |
application.register('service:options', optionsReader.readOptionsKeys(), {singleton: true, instantiate: false}); |
|
37 |
|
|
38 |
} |
|
39 |
|
|
40 |
export default { |
|
41 |
name: 'options', |
|
42 |
initialize |
|
43 |
}; |