FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Refactored the images task a bit so less maintenance is needed when a… · Chhabi/JavaScriptButtons@2ccff73 · GitHub

Repository navigation

Commit 2ccff73

Browse files
committed
Refactored the images task a bit so less maintenance is needed when adding more images later
1 parent e412ea3 commit 2ccff73

5 files changed

Lines changed: 20 additions & 25 deletions

File tree

‎dist/all.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tasks/content.js‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
11
'use strict';
22

33

4-
function base64(str) {
5-
return 'data:image/png;base64,' + str.toString('base64');
6-
}
7-
8-
94
module.exports = function content(grunt) {
105

11-
var src = 'dist/all.js',
12-
tokens = {
13-
logo: '$LOGO$',
14-
primary: '$WORDMARK_PRIMARY$',
15-
secondary: '$WORDMARK_SECONDARY$'
16-
};
6+
var src = 'dist/all.js';
177

188
function processContent(str) {
199
var bundles = grunt.file.expand('locales/**/*.properties'),

‎tasks/images.js‎

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,26 @@ function base64(str) {
88

99
module.exports = function images(grunt) {
1010

11-
var src = 'dist/all.js',
12-
tokens = {
13-
logo: '$LOGO$',
14-
primary: '$WORDMARK_PRIMARY$',
15-
secondary: '$WORDMARK_SECONDARY$'
16-
};
11+
var src = 'dist/all.js';
1712

1813
function processImages(str) {
19-
var logo = grunt.file.read('src/theme/images/logo.png', { encoding: null }),
20-
primary = grunt.file.read('src/theme/images/wordmark_white.png', { encoding: null }),
21-
secondary = grunt.file.read('src/theme/images/wordmark_blue.png', { encoding: null });
22-
23-
str = str.replace(tokens.logo, base64(logo));
24-
str = str.replace(tokens.primary, base64(primary));
25-
str = str.replace(tokens.secondary, base64(secondary));
14+
var files = grunt.file.expand('src/theme/images/*.*'),
15+
templates = {},
16+
name,
17+
token,
18+
contents;
19+
20+
files.forEach(function (file) {
21+
name = file.split(/src\/theme\/images\/(.*)\.(.*)/);
22+
token = '$' + name[1].toUpperCase() + '$';
23+
contents = grunt.file.read(file, { encoding: null });
24+
25+
if (contents) {
26+
str = str.replace(token, base64(contents));
27+
} else {
28+
grunt.fail.warn('Looks like ' + file + ' is missing. Check that it exists.');
29+
}
30+
});
2631

2732
return str;
2833
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL