Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cache images.

  • Loading branch information...
commit 666fd897264730b725c6ea308a0380b635986845 1 parent b7767cd
Assaf Arkin authored
14 lib/passbook.js
View
@@ -177,7 +177,7 @@ IMAGES.forEach(function(key) {
return this;
}
}
-})
+});
// Load all images from the specified directory. Only supported images are
// loaded, nothing bad happens if directory contains other files.
@@ -240,13 +240,21 @@ Passbook.prototype.generate = function(callback) {
var image = self.images[key];
if (typeof image == "string" || image instanceof String) {
// image is a filename, load from disk
- File.readFile(image, done);
+ File.readFile(image, function(error, buffer) {
+ if (!error)
+ self.images[key] = buffer;
+ done(error, buffer);
+ });
} else if (image instanceof Buffer) {
done(null, image);
} else if (typeof image == "function") {
// image is a function, call it to obtain image
try {
- image(done);
+ image(function(error, buffer) {
+ if (!error)
+ self.images[key] = buffer;
+ done(error, buffer);
+ });
} catch (error) {
done(error);
}
15 test/passbook_test.js
View
@@ -103,8 +103,7 @@ describe("Passbook", function() {
describe("generated", function() {
before(function(done) {
var passbook = this.template.createPassbook(this.fields);
- passbook.icon(__dirname + "/resources/icon.png");
- passbook.logo(__dirname + "/resources/logo.png");
+ passbook.loadImagesFrom(__dirname + "/resources");
passbook.generate(function(error, buffer) {
if (error)
done(error);
@@ -140,16 +139,20 @@ describe("Passbook", function() {
it("should contain a manifest", function(done) {
unzip("/tmp/passbook.pkpass", "manifest.json", function(error, buffer) {
assert.deepEqual(JSON.parse(buffer), {
- 'pass.json': 'bcb463e9d94298e2d9757cea4a1af501fe5b45ae',
- 'icon.png': 'e0f0bcd503f6117bce6a1a3ff8a68e36d26ae47f',
- 'logo.png': 'abc97e3b2bc3b0e412ca4a853ba5fd90fe063551'
+ "pass.json": "bcb463e9d94298e2d9757cea4a1af501fe5b45ae",
+ "icon.png": "e0f0bcd503f6117bce6a1a3ff8a68e36d26ae47f",
+ "icon@2x.png": "10e4a72dbb02cc526cef967420553b459ccf2b9e",
+ "logo.png": "abc97e3b2bc3b0e412ca4a853ba5fd90fe063551",
+ "logo@2x.png": "87ca39ddc347646b5625062a349de4d3f06714ac",
+ "strip.png": "e199fc0e2839ad5698b206d5f4b7d8cb2418927c",
+ "strip@2x.png": "ac640c623741c0081fb1592d6353ebb03122244f"
});
done();
});
});
it("should contain a signature", function(done) {
- execFile("signpass", ["-v", "passbook.pkpass"], function(error, stdout) {
+ execFile("signpass", ["-v", "/tmp/passbook.pkpass"], function(error, stdout) {
assert(/\*\*\* SUCCEEDED \*\*\*/.test(stdout), stdout);
done();
})
BIN  test/resources/icon@2x.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  test/resources/logo@2x.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  test/resources/strip.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  test/resources/strip@2x.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Please sign in to comment.
Something went wrong with that request. Please try again.