-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
98 lines (70 loc) · 2.21 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* jshint node: true */
'use strict';
/* Dependencies */
var mergeObjects = require('deepmerge');
var Funnel = require('broccoli-funnel');
var mergeTrees = require('broccoli-merge-trees');
/* Library */
var defaultOptions = require('./lib/default-options');
var fixturesCompiler = require('./lib/fixtures-compiler');
var logger = require('./lib/logger');
module.exports = {
name: 'ember-blog',
/* Private variables */
_app: null,
_htmlbarsPlugin: null,
_templateCompiler: null,
_templatesDir: null,
/* Setup and run everything */
included: function(app) {
var _this = this;
var fixturesOptions = {
appName: app.name,
};
this._app = app;
this._super.included(app);
this.setOptions();
if (this.enabled) {
['fileOptions',
'fixturesDir',
'_templatesDir'].forEach(function(option) {
fixturesOptions[option] = _this[option];
});
/* Add posts and categories fixtures */
app.registry.add('js', {
name: 'blog-fixtures',
ext: 'md', // Not sure this does anything
/* https://github.com/stefanpenner/ember-cli/blob/master/lib/preprocessors/javascript-plugin.js */
toTree: function(tree) {
var templateCompiler = _this._templateCompiler;
var posts = new Funnel(tree, {
include: [new RegExp(/\/posts\/.*.md$/)]
});
var fixturesTree = fixturesCompiler(posts, fixturesOptions, templateCompiler);
return mergeTrees([tree, fixturesTree], {
overwrite: true
});
}
});
} else {
logger.warning(this.name + ' is not enabled.');
}
},
setOptions: function() {
var overridingOptions = this._app.options.blog || {};
var options = mergeObjects(defaultOptions, overridingOptions);
this._templatesDir = '/' + this._app.name + '/templates';
for (var option in options) {
this[option] = options[option];
}
},
setupPreprocessorRegistry: function(type, registry) {
var templatePlugins = registry.load('template');
var htmlbarsPlugin;
if (!templatePlugins.length) {
return;
}
htmlbarsPlugin = templatePlugins[0];
this._templateCompiler = htmlbarsPlugin;
},
};