-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplates.js
More file actions
66 lines (61 loc) · 1.72 KB
/
templates.js
File metadata and controls
66 lines (61 loc) · 1.72 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
63
64
65
66
const HTML = (body) => `
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>これはただの文字列です</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
${body}
</body>
</html>
`;
const TWEET_LIST_VIEW = (tweets) => `
<h1 class="title">ツイート一覧</h1>
<div class="tweet-list">
${tweets
.map((tweet) => `<div class="tweet">${tweet.content}</div>`)
.join("\n")}
</div>
`;
const USER_REGISTER_FORM_VIEW = () => `
<h1 class="title">ユーザー登録</h1>
<form action="/user/register" method="POST">
<label for="name">名前</label>
<input type="text" name="name" id="name" />
<label for="email">メールアドレス</label>
<input type="email" name="email" id="email" />
<button type="submit">登録</button>
</form>
`;
const USER_TWEET_LIST_VIEW = (user, tweets) => `
<h1 class="title">${user.name}さんのツイート一覧</h1>
<div class="tweet-list">
${tweets
.map((tweet) => `<div class="tweet">${tweet.content}</div>`)
.join("\n")}
</div>
`;
const TWEET_FORM_VIEW = (users) => `
<h1 class="title">ツイート</h1>
<form action="/tweet" method="POST">
<label for="content">内容</label>
<textarea name="content" id="content" rows="10"></textarea>
<label for="user_id">ユーザー</label>
<select name="user_id" id="user_id">
${users
.map((user) => `<option value="${user.id}">${user.name}</option>`)
.join("\n")}
</select>
<button type="submit">投稿</button>
</form>
`;
module.exports = {
HTML,
TWEET_LIST_VIEW,
USER_REGISTER_FORM_VIEW,
USER_TWEET_LIST_VIEW,
TWEET_FORM_VIEW,
};