-
-
Notifications
You must be signed in to change notification settings - Fork 278
/
resource.js
106 lines (79 loc) · 1.52 KB
/
resource.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import types from './config/resource-types.js';
class Resource {
constructor (url, filename) {
this.url = url;
this.filename = filename;
this.type = null;
this.depth = 0;
this.parent = null;
this.children = [];
this.saved = false;
this.encoding = 'binary';
}
createChild (url, filename) {
const child = new Resource(url, filename);
let currentDepth = this.getDepth();
child.parent = this;
child.depth = ++currentDepth;
this.children.push(child);
return child;
}
updateChild (oldChild, newChild) {
const index = this.children.indexOf(oldChild);
if (index >= 0) {
this.children[index] = newChild;
}
}
getUrl () {
return this.url;
}
setUrl (url) {
this.url = url;
}
getFilename () {
return this.filename;
}
setFilename (filename) {
this.filename = filename;
}
getText () {
return this.text;
}
setText (text) {
this.text = text;
}
getDepth () {
return this.depth;
}
setType (type) {
this.type = type;
}
getType () {
return this.type;
}
setEncoding (encoding) {
this.encoding = encoding;
}
getEncoding () {
return this.encoding;
}
isHtml () {
return this.getType() === types.html;
}
isCss () {
return this.getType() === types.css;
}
toString () {
return `{ url: "${this.getUrl()}", filename: "${this.getFilename()}", depth: ${this.getDepth()}, type: "${this.getType()}" }`;
}
isSaved () {
return this.saved;
}
setSaved () {
this.saved = true;
}
setMetadata (metadata) {
this.metadata = metadata;
}
}
export default Resource;