forked from jbillimoria/JavaScriptButtons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplates.js
More file actions
36 lines (23 loc) · 835 Bytes
/
templates.js
File metadata and controls
36 lines (23 loc) · 835 Bytes
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
'use strict';
function trim(str) {
return str.replace(/(^\s+|\s+$)/g, '').replace(/(\r\n|\n|\r)/g, '');
}
module.exports = function templates(grunt) {
var src = 'dist/button.js';
function processTemplates(str) {
var files = grunt.file.expand('src/theme/**/*.html'),
templates = {},
name;
files.forEach(function (file) {
name = file.split(/src\/theme\/(.*).html/);
name = name[1];
templates[name] = trim(grunt.file.read(file));
});
return str.replace('\'$TEMPLATES$\'', JSON.stringify(templates));
}
grunt.registerTask('templates', 'Injects templates into the JavaScript', function () {
var out = grunt.file.read(src);
out = processTemplates(out);
grunt.file.write(src, out);
});
};