From 78974ecfe0e8f80718dca53dcc3dbc03967f133e Mon Sep 17 00:00:00 2001 From: ceee Date: Wed, 15 May 2013 23:46:12 +0200 Subject: [PATCH] update plugin name --- Gruntfile.js | 8 +++--- README.md | 8 +++--- package.json | 10 ++++---- tasks/datauri.js | 61 ++++++++++++++++++++++++++++++++++++++++++++ test/datauri_test.js | 20 +++++++++++++++ 5 files changed, 94 insertions(+), 13 deletions(-) create mode 100644 tasks/datauri.js create mode 100644 test/datauri_test.js diff --git a/Gruntfile.js b/Gruntfile.js index 1caf9fb..414e93e 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,6 +1,6 @@ /* - * grunt-base64 - * https://github.com/ceee/grunt-base64 + * grunt-datauri + * https://github.com/ceee/grunt-datauri * * Copyright (c) 2013 Tobias Klika * Licensed under the MIT license. @@ -31,7 +31,7 @@ module.exports = function (grunt) { }, // Configuration to be run (and then tested). - base64: { + datauri: { default: { options: { test: true @@ -58,5 +58,5 @@ module.exports = function (grunt) { grunt.registerTask('test', [ 'clean', 'mkdir:tmp', 'nodeunit', 'clean' ]); - grunt.registerTask('default', [ 'test', 'base64' ]); + grunt.registerTask('default', [ 'test', 'datauri' ]); }; diff --git a/README.md b/README.md index 552e6d7..917f670 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# grunt-base64 +# grunt-datauri > create base64 encoded data-uris for css from images @@ -10,17 +10,17 @@ This plugin requires Grunt `~0.4.0` If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command: ```shell -npm install grunt-base64 --save-dev +npm install grunt-datauri --save-dev ``` Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript: ```js -grunt.loadNpmTasks('grunt-base64'); +grunt.loadNpmTasks('grunt-datauri'); ``` ## Release History -* 2013-05-15 v0.1.0 please wait :P +* 2013-05-15 v0.1.0 basic functionality ## Contributors diff --git a/package.json b/package.json index 8263426..0999d39 100644 --- a/package.json +++ b/package.json @@ -1,23 +1,23 @@ { - "name": "grunt-base64", + "name": "grunt-datauri", "description": "create base64 encoded data-uris for css from images", "version": "0.1.0", - "homepage": "https://github.com/ceee/grunt-base64", + "homepage": "https://github.com/ceee/grunt-datauri", "author": { "name": "Tobias Klika", "url": "http://ceecore.com" }, "repository": { "type": "git", - "url": "git://github.com/ceee/grunt-base64.git" + "url": "git://github.com/ceee/grunt-datauri.git" }, "bugs": { - "url": "https://github.com/ceee/grunt-base64/issues" + "url": "https://github.com/ceee/grunt-datauri/issues" }, "licenses": [ { "type": "MIT", - "url": "https://github.com/ceee/grunt-base64/blob/master/LICENSE-MIT" + "url": "https://github.com/ceee/grunt-datauri/blob/master/LICENSE-MIT" } ], "main": "Gruntfile.js", diff --git a/tasks/datauri.js b/tasks/datauri.js new file mode 100644 index 0000000..90fa8ee --- /dev/null +++ b/tasks/datauri.js @@ -0,0 +1,61 @@ +/* + * grunt-datauri + * https://github.com/ceee/grunt-datauri + * + * Copyright (c) 2013 Tobias Klika + * Licensed under the MIT license. + */ + +'use strict'; + +module.exports = function (grunt) +{ + var path = require('path'); + var fs = require('fs'); + var childProcess = require('child_process'); + var filesize = require('filesize'); + var datauri = require('datauri'); + + grunt.registerMultiTask('datauri', 'create base64 encoded data-uris for css from images', function () + { + 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; + } + }); +}; diff --git a/test/datauri_test.js b/test/datauri_test.js new file mode 100644 index 0000000..b706177 --- /dev/null +++ b/test/datauri_test.js @@ -0,0 +1,20 @@ +'use strict'; + +var grunt = require('grunt'); +var fs = require('fs'); + +exports.datauri = { + + setUp: function( done ) + { + done(); + }, + + datauri_options: function( test ) + { + test.expect( 1 ); + test.equal( 1, 1, "random..." ); + test.done(); + } + +};