forked from simonihmig/ember-cli-preloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (35 loc) · 1.2 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* jshint node: true */
'use strict';
var fs = require('fs');
var path = require('path');
function getInjectionFor(type, filePath) {
var content = [];
content.push('<' + type + ' data-name="preloader">');
content.push(fs.readFileSync(path.join(this.app.project.root, filePath), { encoding: 'utf8' }));
content.push('</' + type + '>');
return content;
}
module.exports = {
name: 'ember-cli-preloader',
included: function(app) {
this.app = app;
this.addonOptions = app.options['ember-cli-preloader'] || {};
this.addonPaths = this.addonOptions['paths'] || {};
if (typeof this.addonOptions.enabled === 'undefined') {
this.addonOptions.enabled = true;
}
},
contentFor: function(name, config) {
if (config.environment === 'test' && !this.addonOptions.enableDuringTests) {
return;
}
if (name === 'body') {
var htmlPath = this.addonPaths['html'] || 'app/preloader/preloader.html';
return getInjectionFor.call(this, 'div', htmlPath);
}
if (this.addonOptions.enabled && name === 'head-footer') {
var cssPath = this.addonPaths['css'] || 'app/preloader/preloader.css';
return getInjectionFor.call(this, 'style', cssPath);
}
}
};