-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTMLGenerator.java
More file actions
62 lines (55 loc) · 2.1 KB
/
HTMLGenerator.java
File metadata and controls
62 lines (55 loc) · 2.1 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
60
61
62
import java.io.IOException;
import java.io.Writer;
import java.util.List;
public class HTMLGenerator {
private final Writer writer;
public HTMLGenerator(Writer writer) {
this.writer = writer;
}
public void generate(List<? extends Content> contents) throws IOException {
this.writer.write(
"""
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>Top 250 Movies</title>
</head>
<body>
<ul style="list-style:none">
""");
final String divTemplate =
"""
<div class="card text-white bg-dark mb-3" style="max-width: 18rem;">
<h4 class="card-header">%s</h4>
<div class="card-body">
<h5 class="card-text mt-1">%s</h5>
<img class="card-img" src="%s" alt="%s">
<p class="card-text mt-2">Nota: %s - Ano: %s</p>
</div>
</div>
""";
for (Content content : contents) {
final String listItemHtml = "<li>" +
String.format(divTemplate,
content.title(),
content.type(),
content.urlImage(),
content.title(),
content.rating(),
content.year())
+ "</li>";
this.writer.write(listItemHtml);
}
this.writer.write(
"""
</ul>
</body>
</html>
"""
);
}
}