-
Notifications
You must be signed in to change notification settings - Fork 7
/
plugin.js
34 lines (30 loc) · 1.08 KB
/
plugin.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
var minify = Npm.require('html-minifier').minify;
var jade = Npm.require('jade');
var jadeOpts = {pretty:true, compileDebug:false};
Plugin.registerSourceHandler('ng.jade', {
isTemplate: true,
archMatching: 'web'
}, function(compileStep) {
var contents = compileStep.read().toString('utf8');
jadeOpts.filename = compileStep.fullInputPath;
contents = jade.compile(contents, jadeOpts)();
var newPath = compileStep.inputPath;
newPath = newPath.replace(/\\/g, "/");
newPath = newPath.replace(".ng.jade", ".html");
var results = 'angular.module(\'angular-meteor\').run([\'$templateCache\', function($templateCache) {' +
'$templateCache.put(\'' + newPath + '\', \'' +
minify(contents.replace(/'/g, "\\'"), {
collapseWhitespace : true,
conservativeCollapse : true,
removeComments : true,
minifyJS : true,
minifyCSS: true,
processScripts : ['text/ng-template']
}) + '\');' +
'}]);';
compileStep.addJavaScript({
path : newPath,
data : results.replace(/\n/g, '\\n'),
sourcePath : compileStep.inputPath
});
});