| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,6 +14,7 @@ module.exports = function (grunt) { | |||
| 14 | 14 | grunt.registerTask('lint', ['jshint', 'eslint']); | |
| 15 | 15 | grunt.registerTask('coverage', ['mocha_istanbul']); | |
| 16 | 16 | grunt.registerTask('mocha', ['mochaTest']); | |
| 17 | + grunt.registerTask('themify', ['templates', 'css', 'images', 'content']); | ||
| 17 | 18 | grunt.registerTask('test', ['lint', 'build', 'coverage']); | |
| 18 | 19 | grunt.registerTask('develop', ['browserify', 'themify']); | |
| 19 | 20 | grunt.registerTask('build', ['browserify', 'themify', 'uglify', 'usebanner']); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,44 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | + module.exports = function content(grunt) { | ||
| 5 | + | ||
| 6 | + var src = 'dist/all.js'; | ||
| 7 | + | ||
| 8 | + function processContent(str) { | ||
| 9 | + var bundles = grunt.file.expand('locales/**/*.properties'), | ||
| 10 | + content = {}, | ||
| 11 | + props, locale; | ||
| 12 | + | ||
| 13 | + bundles.forEach(function (bundle) { | ||
| 14 | + locale = bundle.split(/locales\/([A-Z]{2})\/([a-z]{2})\//); | ||
| 15 | + locale = locale[2] + '_' + locale[1]; | ||
| 16 | + | ||
| 17 | + content[locale] = {}; | ||
| 18 | + | ||
| 19 | + props = grunt.file.read(bundle); | ||
| 20 | + props = props.split(/\n/); | ||
| 21 | + | ||
| 22 | + props.forEach(function (line) { | ||
| 23 | + var pair = line.split(/=(.+)/); | ||
| 24 | + | ||
| 25 | + if (pair[0]) { | ||
| 26 | + content[locale][pair[0]] = pair[1]; | ||
| 27 | + } | ||
| 28 | + }); | ||
| 29 | + }); | ||
| 30 | + | ||
| 31 | + str = str.replace('\'$STRINGS$\'', JSON.stringify(content)); | ||
| 32 | + | ||
| 33 | + return str; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + grunt.registerTask('content', 'Grabs localized content and injects it into the JavaScript', function () { | ||
| 37 | + var out = grunt.file.read(src); | ||
| 38 | + | ||
| 39 | + out = processContent(out); | ||
| 40 | + | ||
| 41 | + grunt.file.write(src, out); | ||
| 42 | + }); | ||
| 43 | + | ||
| 44 | + }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,27 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | + function trim(str) { | ||
| 5 | + return str.replace(/(^\s+|\s+$)/g, '').replace(/(\r\n|\n|\r)/g, ''); | ||
| 6 | + } | ||
| 7 | + | ||
| 8 | + | ||
| 9 | + module.exports = function css(grunt) { | ||
| 10 | + | ||
| 11 | + var src = 'dist/all.js'; | ||
| 12 | + | ||
| 13 | + function processCss(str) { | ||
| 14 | + var styles = trim(grunt.file.read('src/theme/css/index.css')); | ||
| 15 | + | ||
| 16 | + return str.replace('$STYLES$', styles); | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + grunt.registerTask('css', 'Injects css into the JavaScript', function () { | ||
| 20 | + var out = grunt.file.read(src); | ||
| 21 | + | ||
| 22 | + out = processCss(out); | ||
| 23 | + | ||
| 24 | + grunt.file.write(src, out); | ||
| 25 | + }); | ||
| 26 | + | ||
| 27 | + }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,43 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | + function base64(str) { | ||
| 5 | + return 'data:image/png;base64,' + str.toString('base64'); | ||
| 6 | + } | ||
| 7 | + | ||
| 8 | + | ||
| 9 | + module.exports = function images(grunt) { | ||
| 10 | + | ||
| 11 | + var src = 'dist/all.js'; | ||
| 12 | + | ||
| 13 | + function processImages(str) { | ||
| 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 | + }); | ||
| 31 | + | ||
| 32 | + return str; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + grunt.registerTask('images', 'Base64 encodes images and injects them into the JavaScript', function () { | ||
| 36 | + var out = grunt.file.read(src); | ||
| 37 | + | ||
| 38 | + out = processImages(out); | ||
| 39 | + | ||
| 40 | + grunt.file.write(src, out); | ||
| 41 | + }); | ||
| 42 | + | ||
| 43 | + }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,36 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | + function trim(str) { | ||
| 5 | + return str.replace(/(^\s+|\s+$)/g, '').replace(/(\r\n|\n|\r)/g, ''); | ||
| 6 | + } | ||
| 7 | + | ||
| 8 | + | ||
| 9 | + module.exports = function templates(grunt) { | ||
| 10 | + | ||
| 11 | + var src = 'dist/all.js'; | ||
| 12 | + | ||
| 13 | + function processTemplates(str) { | ||
| 14 | + var files = grunt.file.expand('src/theme/**/*.html'), | ||
| 15 | + templates = {}, | ||
| 16 | + name; | ||
| 17 | + | ||
| 18 | + files.forEach(function (file) { | ||
| 19 | + name = file.split(/src\/theme\/(.*).html/); | ||
| 20 | + name = name[1]; | ||
| 21 | + | ||
| 22 | + templates[name] = trim(grunt.file.read(file)); | ||
| 23 | + }); | ||
| 24 | + | ||
| 25 | + return str.replace('\'$TEMPLATES$\'', JSON.stringify(templates)); | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + grunt.registerTask('templates', 'Injects templates into the JavaScript', function () { | ||
| 29 | + var out = grunt.file.read(src); | ||
| 30 | + | ||
| 31 | + out = processTemplates(out); | ||
| 32 | + | ||
| 33 | + grunt.file.write(src, out); | ||
| 34 | + }); | ||
| 35 | + | ||
| 36 | + }; | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments