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
|
package views
import (
"fmt"
"gitrepo.ru/neonxp/gorum/models"
"gitrepo.ru/neonxp/gorum/utils"
"strconv"
)
templ Node(node *models.Node, topics []*models.Node, nodes []*models.Node) {
@Layout(node.Parent) {
switch node.Type {
case models.TopicType:
<h1>{ node.Text }</h1>
<div>
<a href={ templ.URL(fmt.Sprintf("/t/%d/new", node.ID)) }>Новая подтема</a>
</div>
case models.PostType:
<h1>Пост</h1>
@Post(node, 0, false)
}
if len(topics) != 0 {
<table>
<thead>
<tr>
<th>Тема</th>
<th>Тем/Ответов</th>
<th>Дата</th>
<th>Автор</th>
</tr>
</thead>
<tbody>
for _, n := range topics {
@Topic(n)
}
</tbody>
</table>
}
if len(nodes) == 0 {
<strong>Постов нет</strong>
}
for _, n := range nodes {
@Post(n, level(node), true)
}
if isAuthorized(ctx) {
@NewPostForm(node)
} else {
<a href="/login">Войдите</a> чтобы ответить в тему.
}
}
}
templ Topic(n *models.Node) {
<tr>
<td>
<a href={ templ.URL(fmt.Sprintf("/t/%d", n.ID)) }>{ n.Text }</a>
</td>
<td>
{ strconv.Itoa(len(n.Children)) }
</td>
<td>
{ utils.FormatDate(n.CreatedAt) }
</td>
<td>
{ n.Author.Username }
</td>
</tr>
}
css levelStyle(level int) {
margin-left: { fmt.Sprintf("%dem", level) };
}
templ Post(n *models.Node, level int, withFooter bool) {
<article id={ fmt.Sprintf("post%d", n.ID) } class={ levelStyle(level) }>
<header class="post-header">
<span>
{ n.Author.Username }
</span>
<span>
{ utils.FormatDate(n.CreatedAt) }
</span>
</header>
@templ.Raw(utils.MarkdownToHTML(n.Text))
if withFooter {
<footer class="post-header">
<a href={ templ.URL(fmt.Sprintf("/p/%d/new", n.ID)) }>Ответить</a>
<a href={ templ.URL(fmt.Sprintf("/p/%d", n.ID)) }>Ответов: { strconv.Itoa(len(n.Children)) }</a>
</footer>
}
</article>
}
func level(node *models.Node) int {
if node.Type == models.PostType {
return 1
}
return 0
}
|