forked from jbillimoria/JavaScriptButtons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimages.js
More file actions
43 lines (30 loc) · 1.06 KB
/
images.js
File metadata and controls
43 lines (30 loc) · 1.06 KB
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
'use strict';
function base64(str) {
return 'data:image/png;base64,' + str.toString('base64');
}
module.exports = function images(grunt) {
var src = 'dist/button.js';
function processImages(str) {
var files = grunt.file.expand('src/theme/images/*.*'),
templates = {},
name,
token,
contents;
files.forEach(function (file) {
name = file.split(/src\/theme\/images\/(.*)\.(.*)/);
token = '$' + name[1].toUpperCase() + '$';
contents = grunt.file.read(file, { encoding: null });
if (contents) {
str = str.replace(token, base64(contents));
} else {
grunt.fail.warn('Looks like ' + file + ' is missing. Check that it exists.');
}
});
return str;
}
grunt.registerTask('images', 'Base64 encodes images and injects them into the JavaScript', function () {
var out = grunt.file.read(src);
out = processImages(out);
grunt.file.write(src, out);
});
};