-
Notifications
You must be signed in to change notification settings - Fork 0
/
grunt.js
34 lines (28 loc) · 888 Bytes
/
grunt.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
module.exports = function(grunt) {
grunt.initConfig({
watch: {
templates: {
files: 'tpl/*.html',
tasks: 'html2js:directives'
}
},
html2js: {
directives: ['tpl/*.html']
}
});
var TPL = 'angular.module("<%= file %>", []).run(function($templateCache) {\n' +
' $templateCache.put("<%= file %>",\n "<%= content %>");\n' +
'});\n';
var escapeContent = function(content) {
return content.replace(/"/g, '\\"').replace(/\n/g, '" +\n "');
};
grunt.registerMultiTask('html2js', 'Generate js version of html template.', function() {
var files = grunt._watch_changed_files || grunt.file.expand(this.data);
files.forEach(function(file) {
grunt.file.write(file + '.js', grunt.template.process(TPL, {
file: file,
content: escapeContent(grunt.file.read(file))
}));
});
});
};