-
Notifications
You must be signed in to change notification settings - Fork 0
/
card-template.js
62 lines (60 loc) · 2.09 KB
/
card-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
function spellcard (color, data) {
//for (var i in data) {
// data[i] = data[i];//.trim();
//}
var html = '<!------------------------------------------------------------------>\n';
html += '<div class="card '+ color +'"><div class="note">Source: ' + data['source'] + '</div>\n';
html += '<h1>' + data['name'] + '<div>['+ data['level'] + ']</div></h1>\n';
html += '<div>' + wrap(data['short'],'<div>','</div>\n');
html += wrap(data['school'], '<div><strong>School</strong>', wrap(data['sub-school'],' (',')') + wrap(data['school-type'], ' [',']') + '</div>\n');
html += wrap(data['casting-time'],'<div><strong>Casting Time</strong>','</div>\n');
html += wrap(data['components'], '<div><strong>Components</strong>','</div>\n');
html += wrap(data['range'],'<div><strong>Range</strong>', wrap(data['sub-range'],'(',')') + '</div>\n');
html += wrap(data['effect'],'<div><strong>Effect</strong>','</div>\n');
html += wrap(data['target'],'<div><strong>Targets</strong>','</div>\n');
html += wrap(data['duration'],'<div><strong>Duration</strong>', '</div>\n');
html += '<div>'
html += wrap(data['saving'],'<strong>Saving Throw</strong>','\n');
html += wrap(data['resist'],'<strong>Spell Resistance</strong>','\n');
html += '</div></div><div><h2>Description</h2><div>\n';
html += data['text'];
html += '</div></div></div>\n';
return html;
}
function genDict(opts, defaults=null) {
var dict = {
"name":'Title',
"school":'',
"sub-school":'',
"school-type":'',
"casting-time":'',
"components":'',
"range":'',
"sub-range":'',
"effect":'',
"target":'',
"duration":'',
"saving":'',
"resist":'',
"text":'Main text.',
"source":'Core',
"level":'0',
"short":''
};
if (defaults) {
for (var key in defaults) {
dict[key] = defaults[key];
}
}
for (var key in opts) {
dict[key] = opts[key];
}
return dict;
}
function wrap(data, left, right) {
if (typeof data == 'string' && data != '') {
var ret = left.concat(data)
return ret.concat(right);
}
return '';
}