forked from HackYourFuture/JavaScript3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRepository.js
More file actions
59 lines (51 loc) · 1.61 KB
/
Repository.js
File metadata and controls
59 lines (51 loc) · 1.61 KB
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
'use strict';
/* global Util */
// eslint-disable-next-line no-unused-vars
class Repository {
constructor(repository) {
this.repository = repository;
// this.index = index;
}
/**
* Render the repository info to the DOM.
* @param {HTMLElement} container The container element in which to render the repository.
*/
render(container) {
const ul = Util.createAndAppend('ul', container);
const description = Util.createAndAppend('li', ul);
Util.createAndAppend('span', description, { text: 'Description' });
Util.createAndAppend('span', description, {
text: this.repository.description,
class: 'result',
});
const name = Util.createAndAppend('li', ul);
Util.createAndAppend('span', name, { text: 'Link' });
Util.createAndAppend('a', name, {
text: this.repository.name.toUpperCase(),
class: 'result',
target: '_blank',
href: this.repository.html_url,
});
const forks = Util.createAndAppend('li', ul);
Util.createAndAppend('span', forks, { text: 'Forks' });
Util.createAndAppend('span', forks, { text: this.repository.forks, class: 'result' });
const updated = Util.createAndAppend('li', ul);
Util.createAndAppend('span', updated, { text: 'Updated' });
Util.createAndAppend('span', updated, {
text: this.repository.updated_at,
class: 'result',
});
}
/**
* Returns an array of contributors as a promise
*/
fetchContributors() {
return Util.fetchJSON(this.repository.contributors_url);
}
/**
* Returns the name of the repository
*/
name() {
return this.repository.name;
}
}