add basic functionality
This commit is contained in:
+21
-3
@@ -10,6 +10,7 @@
|
||||
|
||||
module.exports = function (grunt) {
|
||||
grunt.initConfig({
|
||||
|
||||
jshint: {
|
||||
all: [
|
||||
'Gruntfile.js',
|
||||
@@ -20,11 +21,29 @@ module.exports = function (grunt) {
|
||||
jshintrc: '.jshintrc'
|
||||
}
|
||||
},
|
||||
|
||||
clean: {
|
||||
test: ['tmp']
|
||||
},
|
||||
|
||||
nodeunit: {
|
||||
tasks: ['test/*_test.js']
|
||||
},
|
||||
|
||||
// Configuration to be run (and then tested).
|
||||
base64: {
|
||||
default: {
|
||||
options: {
|
||||
test: true
|
||||
},
|
||||
src: [
|
||||
"test/fixtures/test-png.png",
|
||||
"test/fixtures/test-gif.gif",
|
||||
"test/fixtures/test-jpg.jpg",
|
||||
"test/fixtures/test-bmp.bmp"
|
||||
],
|
||||
dest: "tmp/base64.css"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -34,11 +53,10 @@ module.exports = function (grunt) {
|
||||
grunt.loadNpmTasks('grunt-contrib-jshint');
|
||||
grunt.loadNpmTasks('grunt-contrib-nodeunit');
|
||||
grunt.loadNpmTasks('grunt-contrib-internal');
|
||||
grunt.loadNpmTasks('grunt-base64');
|
||||
|
||||
grunt.registerTask('mkdir', grunt.file.mkdir);
|
||||
|
||||
|
||||
grunt.registerTask('test', [ 'clean', 'mkdir:tmp', 'nodeunit', 'clean' ]);
|
||||
|
||||
|
||||
grunt.registerTask('default', [ 'test', 'base64' ]);
|
||||
};
|
||||
|
||||
+2
-1
@@ -28,7 +28,8 @@
|
||||
"test": "grunt test"
|
||||
},
|
||||
"dependencies": {
|
||||
"filesize": "~1.7.9"
|
||||
"filesize": "~1.7.9",
|
||||
"datauri": "~0.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"grunt-contrib-internal": "~0.4.3",
|
||||
|
||||
+41
-2
@@ -14,9 +14,48 @@ module.exports = function (grunt)
|
||||
var fs = require('fs');
|
||||
var childProcess = require('child_process');
|
||||
var filesize = require('filesize');
|
||||
var datauri = require('datauri');
|
||||
|
||||
grunt.registerMultiTask('base64', 'create base64 encoded data-uris for css from images', function ()
|
||||
{
|
||||
var options = this.options();
|
||||
});
|
||||
var options = this.options({
|
||||
|
||||
});
|
||||
|
||||
|
||||
this.files.forEach(function(f)
|
||||
{
|
||||
// filter valid files and map data uri generation
|
||||
var data = f.src.filter( fileExists ).map( generateDataUri ).join('\n');
|
||||
|
||||
// Write the destination file.
|
||||
grunt.file.write(f.dest, data);
|
||||
|
||||
grunt.log.writeln('File "' + f.dest + '" created.');
|
||||
});
|
||||
|
||||
|
||||
// generates a datauri object from file
|
||||
// ~~~~~~~~~~~~~~~~~~~~~
|
||||
function generateDataUri( filepath )
|
||||
{
|
||||
var dataObj = new datauri( filepath );
|
||||
|
||||
return dataObj.getCss();
|
||||
}
|
||||
|
||||
|
||||
// Warn on and remove invalid source files (if nonull was set).
|
||||
// ~~~~~~~~~~~~~~~~~~~~~
|
||||
function fileExists( filepath )
|
||||
{
|
||||
if (!grunt.file.exists(filepath))
|
||||
{
|
||||
grunt.log.warn('source file "' + filepath + '" not found.');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -3,4 +3,17 @@ var grunt = require('grunt');
|
||||
var fs = require('fs');
|
||||
|
||||
exports.imagemin = {
|
||||
|
||||
setUp: function( done )
|
||||
{
|
||||
done();
|
||||
},
|
||||
|
||||
base64_options: function( test )
|
||||
{
|
||||
test.expect( 1 );
|
||||
test.equal( 1, 1, "random..." );
|
||||
test.done();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Vendored
BIN
Binary file not shown.
|
After Width: | Height: | Size: 29 KiB |
Vendored
BIN
Binary file not shown.
|
After Width: | Height: | Size: 458 B |
Vendored
BIN
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
Vendored
BIN
Binary file not shown.
|
After Width: | Height: | Size: 4.9 KiB |
Reference in New Issue
Block a user