spritesmith
Advanced tools
Comparing version 0.3.5 to 0.3.7
{ | ||
"name": "spritesmith", | ||
"version": "0.3.5", | ||
"version": "0.3.7", | ||
"description": "Utility that takes images and creates a spritesheet with JSON sprite data", | ||
@@ -5,0 +5,0 @@ "main": "src/smith.js", |
@@ -5,2 +5,6 @@ Spritesmith | ||
Once you have satisfied the [requirements](#requirements), spritesmith can be installed via `npm install spritesmith`. | ||
Spritesmith is also available as a [grunt plugin](https://github.com/Ensighten/grunt-spritesmith). | ||
Requirements | ||
@@ -95,2 +99,2 @@ ------------ | ||
Copyright (c) 2012 Ensighten | ||
Licensed under the MIT license. | ||
Licensed under the MIT license. |
@@ -72,2 +72,30 @@ var smith = require('../src/smith.js'), | ||
describe('An empty array', function () { | ||
var sprites = []; | ||
describe('when processed via spritesmith', function () { | ||
before(function (done) { | ||
var that = this; | ||
// Attempt to create a spritesheet | ||
smith({'src': sprites}, function (err, result) { | ||
// If there is an error, throw it | ||
if (err) { throw err; } | ||
// Save the result and callback | ||
that.result = result; | ||
done(err); | ||
}); | ||
}); | ||
it('renders an empty spritesheet', function () { | ||
assert.strictEqual(this.result.image, ''); | ||
}); | ||
it('returns an empty coordinate mapping', function () { | ||
assert.deepEqual(this.result.coordinates, {}); | ||
}); | ||
}); | ||
}); | ||
function assertSpritesheet() { | ||
@@ -74,0 +102,0 @@ var result = this.result, |
@@ -96,2 +96,8 @@ var async = require('async'), | ||
function exportCanvas (canvas, cb) { | ||
// If there are no items to pack, skip export | ||
var items = packedObj.items; | ||
if (items.length === 0) { | ||
return cb(null, ''); | ||
} | ||
// Create a CanvasSmithy | ||
@@ -101,3 +107,3 @@ var canvasSmith = new CanvasSmith(canvas); | ||
// Add the images onto canvasSmith | ||
canvasSmith.addImages(packedObj.items); | ||
canvasSmith.addImages(items); | ||
@@ -104,0 +110,0 @@ // Export our canvas |
@@ -37,3 +37,3 @@ var fs = require('fs'), | ||
var imgData = [], | ||
err = ""; | ||
errOccurred = false; | ||
@@ -47,5 +47,14 @@ // On data, add it to imgData | ||
// On error, save it | ||
stream.on('error', function (_err) { | ||
err += _err; | ||
// DEV: Originally, this collected errors for stream.on('end') but Cairo won't callback on error =( | ||
// On error | ||
stream.on('error', function (err) { | ||
// If this is the first error | ||
if (!errOccurred) { | ||
// Make a note that it occurred and callback | ||
errOccurred = true; | ||
cb(err); | ||
} else { | ||
// Otherwise, abandon ship and notify the user | ||
console.error('MULTIPLE SPRITESMTIH ERRORS: ', err); | ||
} | ||
}); | ||
@@ -55,12 +64,10 @@ | ||
stream.on('end', function () { | ||
// If there was an error, callback with it | ||
if (err) { | ||
cb(err); | ||
} else { | ||
// Otherwise, join together image data, put it into the retObj | ||
var retStr = imgData.join(''); | ||
// If there was an error, do nothing (callback already fired) | ||
if (errOccurred) { | ||
return; | ||
} | ||
// Callback with no error | ||
cb(null, retStr); | ||
} | ||
// Otherwise, join together image data and callback | ||
var retStr = imgData.join(''); | ||
cb(null, retStr); | ||
}); | ||
@@ -67,0 +74,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
120322
765
99