forked from code0100fun/ember-cli-emblem-hbs-printer
/
index.js
68 lines (58 loc) · 1.92 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
/* jshint node: true */
'use strict';
var Filter = require('broccoli-filter');
var checker = require('ember-cli-version-checker');
var path = require('path');
var defaults = require('lodash').defaults;
function TemplateCompiler (inputTree, options) {
if (!(this instanceof TemplateCompiler)) {
return new TemplateCompiler(inputTree, options);
}
Filter.call(this, inputTree, options); // this._super()
this.options = options || {};
this.inputTree = inputTree;
this.compile = this.options.emblemCompiler || require('emblem').default.compile;
}
TemplateCompiler.prototype = Object.create(Filter.prototype);
TemplateCompiler.prototype.constructor = TemplateCompiler;
TemplateCompiler.prototype.extensions = ['embl', 'emblem', 'em'];
TemplateCompiler.prototype.targetExtension = 'hbs';
TemplateCompiler.prototype.processString = function (string, relativePath) {
return this.compile(string);
}
module.exports = {
name: 'ember-cli-emblem',
shouldSetupRegistryInIncluded: function() {
return !checker.isAbove(this, '0.2.0');
},
getConfig: function() {
var brocfileConfig = {};
var emblemOptions = defaults(this.project.config(process.env.EMBER_ENV).emblemOptions || {},
brocfileConfig, {
blueprints: true
});
return emblemOptions;
},
blueprintsPath: function() {
if (this.getConfig().blueprints) {
return path.join(__dirname, 'blueprints');
}
},
setupPreprocessorRegistry: function(type, registry) {
var addonContext = this;
var compiler = {
name: 'ember-cli-emblem',
ext: ['embl', 'emblem', 'em'],
toTree: function(tree) {
return TemplateCompiler(tree, addonContext.getConfig());
}
};
registry.add('template', compiler);
},
included: function(app){
this._super.included.apply(this, arguments);
if (this.shouldSetupRegistryInIncluded()) {
this.setupPreprocessorRegistry('parent', app.registry);
}
}
};