This repository has been archived by the owner on Dec 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathtemplate.js
77 lines (62 loc) · 2.12 KB
/
template.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Passbook are created from templates
var applyImageMethods = require("./images");
var Pass = require("./pass");
// Supported passbook styles.
var STYLES = [ "boardingPass", "coupon", "eventTicket", "generic", "storeCard" ];
// Template will have accessor methods for these fields.
var TEMPLATE = [ "passTypeIdentifier", "teamIdentifier",
"backgroundColor", "foregroundColor", "labelColor", "logoText",
"organizationName", "suppressStripShine", "webServiceURL"];
// Create a new template.
//
// style - Pass style (coupon, eventTicket, etc)
// fields - Pass fields (passTypeIdentifier, teamIdentifier, etc)
function Template(style, fields) {
if (!~STYLES.indexOf(style))
throw new Error("Unsupported pass style " + style);
this.style = style;
this.fields = {};
for (var key in fields)
this.fields[key] = fields[key];
this.keysPath = "keys";
this.images = {};
}
applyImageMethods(Template);
// Sets path to directory containing keys and password for accessing keys.
//
// path - Path to directory containing key files (default is 'keys')
// password - Password to use with keys
Template.prototype.keys = function(path, password) {
if (path)
this.keysPath = path;
if (password)
this.password = password;
};
// Create a new pass from a template.
Template.prototype.createPass = function(fields) {
// Combine template and pass fields
var combined = {};
for (var k1 in this.fields)
combined[k1] = this.fields[k1];
for (var k2 in fields)
combined[k2] = fields[k2];
return new Pass(this, combined, this.images);
};
// Accessor methods for template fields.
//
// Call with an argument to set field and return self, call with no argument to
// get field value.
//
// template.passTypeIdentifier("com.example.mypass");
// console.log(template.passTypeIdentifier());
TEMPLATE.forEach(function(key) {
Template.prototype[key] = function(value) {
if (arguments.length === 0) {
return this.fields[key];
} else {
this.fields[key] = value;
return this;
}
};
});
module.exports = Template;