This repository has been archived by the owner on Feb 28, 2019. It is now read-only.
forked from Jasonette/Jasonette-Web
-
Notifications
You must be signed in to change notification settings - Fork 5
/
section.js
60 lines (58 loc) · 1.68 KB
/
section.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
var Section = {
build: function(input) {
var output = [];
var h = Section.header(input);
if (h) output = output.concat(h);
var i = Section.items(input);
if (i) output = output.concat({
class: "section-items", $components: i
});
return output;
},
header: function(input) {
if (input.header) {
var output = {
class: "section-header"
};
if (input.header.style) {
output["style"] = {};
if (input.header.style.background) {
output["style"]["backgroundColor"] = input.header.style.background;
}
if (input.header.style.padding) {
output["style"]["padding"] = input.header.style.padding;
}
if (input.header.style.width) {
output["style"]["width"] = input.header.style.width;
}
if (input.header.style.height) {
output["style"]["height"] = input.header.style.height;
}
}
output["$components"] = [Item.build(input.header)];
return output;
} else {
return null;
}
},
items: function(input) {
if (input.items) {
return input.items.map(function(item) {
var style = {};
if (item.style) {
if (item.style.background) style.backgroundColor = item.style.background;
if (item.style.padding) style.padding = item.style.padding + 'px';
if (item.style.width) style.width = item.style.width + 'px';
if (item.style.height) style.height = item.style.height + 'px';
}
return {
class: "section-item",
$components: [Item.build(item)],
style: style
}
})
} else {
return null;
}
}
}