aboutsummaryrefslogtreecommitdiff
path: root/views
diff options
context:
space:
mode:
authorAlexander NeonXP Kiryukhin <i@neonxp.ru>2024-07-21 19:26:56 +0300
committerAlexander NeonXP Kiryukhin <i@neonxp.ru>2024-07-21 19:28:56 +0300
commitce3111b0efe91e275ce070f9511b5b1b9801a46d (patch)
tree09fa4f10dfb1e17761339c798eefa73c6b18484f /views
parente9a64f3b41b5eae47dec7c0ecfd1caae83136abc (diff)
Множество улучшенийv0.0.2
Diffstat (limited to 'views')
-rw-r--r--views/csrf.templ3
-rw-r--r--views/csrf_templ.go31
-rw-r--r--views/error.templ8
-rw-r--r--views/error_templ.go6
-rw-r--r--views/error_templ.txt1
-rw-r--r--views/layouts.templ27
-rw-r--r--views/layouts_templ.go76
-rw-r--r--views/layouts_templ.txt7
-rw-r--r--views/login.templ2
-rw-r--r--views/login_templ.go6
-rw-r--r--views/login_templ.txt2
-rw-r--r--views/new-node.templ30
-rw-r--r--views/new-node_templ.go85
-rw-r--r--views/new-node_templ.txt5
-rw-r--r--views/new.templ51
-rw-r--r--views/new_templ.go271
-rw-r--r--views/nodes.templ93
-rw-r--r--views/nodes_templ.go254
-rw-r--r--views/nodes_templ.txt18
-rw-r--r--views/register.templ2
-rw-r--r--views/register_templ.go8
-rw-r--r--views/register_templ.txt3
22 files changed, 687 insertions, 302 deletions
diff --git a/views/csrf.templ b/views/csrf.templ
index 2bb3545..c019d4c 100644
--- a/views/csrf.templ
+++ b/views/csrf.templ
@@ -1,7 +1,6 @@
package views
-import "github.com/labstack/echo/v4"
templ CSRF() {
- <input type="hidden" name={echo.HeaderXCSRFToken} value={ ctx.Value("csrf").(string) }/>
+ // <input type="hidden" name={echo.HeaderXCSRFToken} value={ ctx.Value("csrf").(string) } />
}
diff --git a/views/csrf_templ.go b/views/csrf_templ.go
new file mode 100644
index 0000000..53a7118
--- /dev/null
+++ b/views/csrf_templ.go
@@ -0,0 +1,31 @@
+// Code generated by templ - DO NOT EDIT.
+
+// templ: version: v0.2.747
+package views
+
+//lint:file-ignore SA4006 This context is only used if a nested component is present.
+
+import "github.com/a-h/templ"
+import templruntime "github.com/a-h/templ/runtime"
+
+func CSRF() templ.Component {
+ return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
+ templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
+ templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
+ if !templ_7745c5c3_IsBuffer {
+ defer func() {
+ templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err == nil {
+ templ_7745c5c3_Err = templ_7745c5c3_BufErr
+ }
+ }()
+ }
+ ctx = templ.InitializeContext(ctx)
+ templ_7745c5c3_Var1 := templ.GetChildren(ctx)
+ if templ_7745c5c3_Var1 == nil {
+ templ_7745c5c3_Var1 = templ.NopComponent
+ }
+ ctx = templ.ClearChildren(ctx)
+ return templ_7745c5c3_Err
+ })
+}
diff --git a/views/error.templ b/views/error.templ
index d3a4a32..3e857ef 100644
--- a/views/error.templ
+++ b/views/error.templ
@@ -1,8 +1,8 @@
package views
templ ErrorPage(err error) {
- @Layout() {
- <h1>Ошибка</h1>
- {err.Error()}
- }
+ @Layout(nil) {
+ <h1>Ошибка</h1>
+ { err.Error() }
+ }
}
diff --git a/views/error_templ.go b/views/error_templ.go
index 66d40fd..8513d1d 100644
--- a/views/error_templ.go
+++ b/views/error_templ.go
@@ -38,14 +38,14 @@ func ErrorPage(err error) templ.Component {
}()
}
ctx = templ.InitializeContext(ctx)
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<h1>Ошибка</h1>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(err.Error())
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/error.templ`, Line: 6, Col: 20}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/error.templ`, Line: 6, Col: 15}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
if templ_7745c5c3_Err != nil {
@@ -53,7 +53,7 @@ func ErrorPage(err error) templ.Component {
}
return templ_7745c5c3_Err
})
- templ_7745c5c3_Err = Layout().Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer)
+ templ_7745c5c3_Err = Layout(nil).Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
diff --git a/views/error_templ.txt b/views/error_templ.txt
deleted file mode 100644
index d3a792d..0000000
--- a/views/error_templ.txt
+++ /dev/null
@@ -1 +0,0 @@
-<h1>Ошибка</h1>
diff --git a/views/layouts.templ b/views/layouts.templ
index 3db6f1b..f1c2deb 100644
--- a/views/layouts.templ
+++ b/views/layouts.templ
@@ -2,11 +2,12 @@ package views
import (
"context"
+ "fmt"
"gitrepo.ru/neonxp/gorum/contextlib"
"gitrepo.ru/neonxp/gorum/models"
)
-templ Layout() {
+templ Layout(parent *models.Node) {
<!DOCTYPE html>
<html lang="ru">
<head>
@@ -14,7 +15,7 @@ templ Layout() {
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="color-scheme" content="light dark"/>
<link rel="stylesheet" href={ "/assets/css/pico." + ctx.Value(contextlib.ThemeKey).(string) + ".min.css" }/>
- <link rel="stylesheet" href="/assets/css/style.css" />
+ <link rel="stylesheet" href="/assets/css/style.css"/>
<title>Gorum</title>
</head>
<body>
@@ -23,9 +24,23 @@ templ Layout() {
<li>
<strong>Gorum BBS</strong>
</li>
- <li>
- <a href="/">Список тем</a>
- </li>
+ if parent != nil {
+ <li>
+ <a href="/">Список тем</a>
+ </li>
+ <li>
+ switch parent.Type {
+ case models.PostType:
+ <a href={ templ.URL(fmt.Sprintf("/p/%d", parent.ID)) }>На уровень выше</a>
+ case models.TopicType:
+ <a href={ templ.URL(fmt.Sprintf("/t/%d", parent.ID)) }>К предыдущей теме</a>
+ }
+ </li>
+ } else {
+ <li>
+ <a href="/">Список тем</a>
+ </li>
+ }
</ul>
<ul>
if isAuthorized(ctx) {
@@ -42,7 +57,7 @@ templ Layout() {
{ children... }
</main>
<footer class="container-fluid">
- <small>Работает на <a href="https://gorum.tech/">Gorum</a>.</small>
+ <small>Работает на <a href="https://neonxp.ru/gorum">Gorum</a>.</small>
</footer>
</body>
</html>
diff --git a/views/layouts_templ.go b/views/layouts_templ.go
index 4fdcb75..6191925 100644
--- a/views/layouts_templ.go
+++ b/views/layouts_templ.go
@@ -10,11 +10,12 @@ import templruntime "github.com/a-h/templ/runtime"
import (
"context"
+ "fmt"
"gitrepo.ru/neonxp/gorum/contextlib"
"gitrepo.ru/neonxp/gorum/models"
)
-func Layout() templ.Component {
+func Layout(parent *models.Node) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
@@ -32,48 +33,97 @@ func Layout() templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<!doctype html><html lang=\"ru\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><meta name=\"color-scheme\" content=\"light dark\"><link rel=\"stylesheet\" href=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var2 string
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs("/assets/css/pico." + ctx.Value(contextlib.ThemeKey).(string) + ".min.css")
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/layouts.templ`, Line: 16, Col: 107}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/layouts.templ`, Line: 17, Col: 107}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"><link rel=\"stylesheet\" href=\"/assets/css/style.css\"><title>Gorum</title></head><body><nav class=\"container-fluid\"><ul><li><strong>Gorum BBS</strong></li>")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ if parent != nil {
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<li><a href=\"/\">Список тем</a></li><li>")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ switch parent.Type {
+ case models.PostType:
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<a href=\"")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var3 templ.SafeURL = templ.URL(fmt.Sprintf("/p/%d", parent.ID))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var3)))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">На уровень выше</a>")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ case models.TopicType:
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<a href=\"")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var4 templ.SafeURL = templ.URL(fmt.Sprintf("/t/%d", parent.ID))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var4)))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">К предыдущей теме</a>")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</li>")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ } else {
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<li><a href=\"/\">Список тем</a></li>")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</ul><ul>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if isAuthorized(ctx) {
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 3)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" <li>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var3 string
- templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(getUser(ctx).Username)
+ var templ_7745c5c3_Var5 string
+ templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(getUser(ctx).Username)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/layouts.templ`, Line: 33, Col: 33}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/layouts.templ`, Line: 48, Col: 33}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 4)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</li><li><form action=\"/logout\" method=\"POST\"><input type=\"submit\" value=\"Выход\"></form></li>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else {
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 5)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<li><a href=\"/login\">Вход</a></li><li><a href=\"/register\">Регистрация</a></li>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 6)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</ul></nav><main class=\"container\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -81,7 +131,7 @@ func Layout() templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 7)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</main><footer class=\"container-fluid\"><small>Работает на <a href=\"https://neonxp.ru/gorum\">Gorum</a>.</small></footer></body></html>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
diff --git a/views/layouts_templ.txt b/views/layouts_templ.txt
deleted file mode 100644
index ed4ab5e..0000000
--- a/views/layouts_templ.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-<!doctype html><html lang=\"ru\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><meta name=\"color-scheme\" content=\"light dark\"><link rel=\"stylesheet\" href=\"
-\"><link rel=\"stylesheet\" href=\"/assets/css/style.css\"><title>Gorum</title></head><body><nav class=\"container-fluid\"><ul><li><strong>Gorum BBS</strong></li><li><a href=\"/\">Список тем</a></li></ul><ul>
- <li>
-</li><li><form action=\"/logout\" method=\"POST\"><input type=\"submit\" value=\"Выход\"></form></li>
-<li><a href=\"/login\">Вход</a></li><li><a href=\"/register\">Регистрация</a></li>
-</ul></nav><main class=\"container\">
-</main><footer class=\"container-fluid\"><small>Работает на <a href=\"https://gorum.tech/\">Gorum</a>.</small></footer></body></html>
diff --git a/views/login.templ b/views/login.templ
index 7f3a385..6c897c6 100644
--- a/views/login.templ
+++ b/views/login.templ
@@ -1,7 +1,7 @@
package views
templ Login(email string) {
- @Layout() {
+ @Layout(nil) {
<h1>Вход</h1>
<form method="post">
<label for="email">Электропочта:</label>
diff --git a/views/login_templ.go b/views/login_templ.go
index d575513..034133f 100644
--- a/views/login_templ.go
+++ b/views/login_templ.go
@@ -38,7 +38,7 @@ func Login(email string) templ.Component {
}()
}
ctx = templ.InitializeContext(ctx)
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<h1>Вход</h1><form method=\"post\"><label for=\"email\">Электропочта:</label> <input type=\"email\" id=\"email\" name=\"email\" required=\"true\" placeholder=\"имя@mail.ru\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -51,13 +51,13 @@ func Login(email string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"> <label for=\"password\">Пароль:</label> <input type=\"password\" id=\"password\" name=\"password\" required=\"true\" placeholder=\"пароль\"> <label for=\"remember\"><input type=\"checkbox\" id=\"remember\" name=\"remember\" checked=\"checked\"> Запомнить меня?</label> <input type=\"submit\" value=\"Войти\"></form>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return templ_7745c5c3_Err
})
- templ_7745c5c3_Err = Layout().Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer)
+ templ_7745c5c3_Err = Layout(nil).Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
diff --git a/views/login_templ.txt b/views/login_templ.txt
deleted file mode 100644
index 7b12aee..0000000
--- a/views/login_templ.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-<h1>Вход</h1><form method=\"post\"><label for=\"email\">Электропочта:</label> <input type=\"email\" id=\"email\" name=\"email\" required=\"true\" placeholder=\"имя@mail.ru\" value=\"
-\"> <label for=\"password\">Пароль:</label> <input type=\"password\" id=\"password\" name=\"password\" required=\"true\" placeholder=\"пароль\"> <label for=\"remember\"><input type=\"checkbox\" id=\"remember\" name=\"remember\" checked=\"checked\"> Запомнить меня?</label> <input type=\"submit\" value=\"Войти\"></form>
diff --git a/views/new-node.templ b/views/new-node.templ
deleted file mode 100644
index b92dbba..0000000
--- a/views/new-node.templ
+++ /dev/null
@@ -1,30 +0,0 @@
-package views
-
-import (
- "fmt"
- "gitrepo.ru/neonxp/gorum/models"
- "strconv"
-)
-
-templ NewNode(parent *models.Node) {
- <details>
- <summary>Создать топик</summary>
- <form method="post" action={ templ.URL(fmt.Sprintf("/n/%d/new", parent.ID)) }>
- @CSRF()
- <input type="hidden" name="type" value={ strconv.Itoa(int(models.TopicType)) }/>
- <label for="text">Топик</label>
- <input type="text" name="text" id="text" placeholder="имя темы..."/>
- <input type="submit" value="Создать"/>
- </form>
- </details>
- <details>
- <summary>Создать пост</summary>
- <form method="post" action={ templ.URL(fmt.Sprintf("/n/%d/new", parent.ID)) }>
- @CSRF()
- <input type="hidden" name="type" value={ strconv.Itoa(int(models.PostType)) }/>
- <label for="text">Текст</label>
- <textarea name="text" id="text" placeholder="текст..." rows="10"></textarea>
- <input type="submit" value="Создать"/>
- </form>
- </details>
-}
diff --git a/views/new-node_templ.go b/views/new-node_templ.go
deleted file mode 100644
index b838227..0000000
--- a/views/new-node_templ.go
+++ /dev/null
@@ -1,85 +0,0 @@
-// Code generated by templ - DO NOT EDIT.
-
-// templ: version: v0.2.747
-package views
-
-//lint:file-ignore SA4006 This context is only used if a nested component is present.
-
-import "github.com/a-h/templ"
-import templruntime "github.com/a-h/templ/runtime"
-
-import (
- "fmt"
- "gitrepo.ru/neonxp/gorum/models"
- "strconv"
-)
-
-func NewNode(parent *models.Node) templ.Component {
- return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
- templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
- templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
- if !templ_7745c5c3_IsBuffer {
- defer func() {
- templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
- if templ_7745c5c3_Err == nil {
- templ_7745c5c3_Err = templ_7745c5c3_BufErr
- }
- }()
- }
- ctx = templ.InitializeContext(ctx)
- templ_7745c5c3_Var1 := templ.GetChildren(ctx)
- if templ_7745c5c3_Var1 == nil {
- templ_7745c5c3_Var1 = templ.NopComponent
- }
- ctx = templ.ClearChildren(ctx)
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1)
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- var templ_7745c5c3_Var2 templ.SafeURL = templ.URL(fmt.Sprintf("/n/%d/new", parent.ID))
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var2)))
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2)
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- var templ_7745c5c3_Var3 string
- templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(int(models.TopicType)))
- if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/new-node.templ`, Line: 13, Col: 79}
- }
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 3)
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- var templ_7745c5c3_Var4 templ.SafeURL = templ.URL(fmt.Sprintf("/n/%d/new", parent.ID))
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var4)))
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 4)
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- var templ_7745c5c3_Var5 string
- templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(int(models.PostType)))
- if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/new-node.templ`, Line: 22, Col: 78}
- }
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 5)
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- return templ_7745c5c3_Err
- })
-}
diff --git a/views/new-node_templ.txt b/views/new-node_templ.txt
deleted file mode 100644
index 4904f81..0000000
--- a/views/new-node_templ.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-<details><summary>Создать топик</summary><form method=\"post\" action=\"
-\"><input type=\"hidden\" name=\"type\" value=\"
-\"> <label for=\"text\">Топик</label> <input type=\"text\" name=\"text\" id=\"text\" placeholder=\"имя темы...\"> <input type=\"submit\" value=\"Создать\"></form></details> <details><summary>Создать пост</summary><form method=\"post\" action=\"
-\"><input type=\"hidden\" name=\"type\" value=\"
-\"> <label for=\"text\">Текст</label> <textarea name=\"text\" id=\"text\" placeholder=\"текст...\" rows=\"10\"></textarea> <input type=\"submit\" value=\"Создать\"></form></details>
diff --git a/views/new.templ b/views/new.templ
new file mode 100644
index 0000000..c83a4a9
--- /dev/null
+++ b/views/new.templ
@@ -0,0 +1,51 @@
+package views
+
+import (
+ "fmt"
+ "gitrepo.ru/neonxp/gorum/models"
+ "gitrepo.ru/neonxp/gorum/utils"
+ "strconv"
+)
+
+templ NewPost(parent *models.Node) {
+ @Layout(parent.Parent) {
+ <article>
+ <header class="post-header">
+ <span>
+ { parent.Author.Username }
+ </span>
+ <span>
+ { utils.FormatDate(parent.CreatedAt) }
+ </span>
+ </header>
+ @templ.Raw(utils.MarkdownToHTML(parent.Text))
+ </article>
+ @NewPostForm(parent)
+ }
+}
+templ NewTopic(parent *models.Node) {
+ @Layout(parent.Parent) {
+ <h1>{parent.Text}</h1>
+ @NewTopicForm(parent)
+ }
+}
+
+templ NewPostForm(parent *models.Node) {
+ <form method="post" action={ templ.URL(fmt.Sprintf("/p/%d/new", parent.ID)) }>
+ @CSRF()
+ <input type="hidden" name="type" value={ strconv.Itoa(int(models.PostType)) }/>
+ <label for="text"><strong>Ответ</strong></label>
+ <textarea name="text" id="text" placeholder="текст..." rows="5"></textarea>
+ <input type="submit" value="Создать"/>
+ </form>
+}
+
+templ NewTopicForm(parent *models.Node) {
+ <form method="post" action={ templ.URL(fmt.Sprintf("/t/%d/new", parent.ID)) }>
+ @CSRF()
+ <input type="hidden" name="type" value={ strconv.Itoa(int(models.TopicType)) }/>
+ <label for="text"><strong>Новая тема</strong></label>
+ <input type="text" name="text" id="text" placeholder="название темы..." />
+ <input type="submit" value="Создать"/>
+ </form>
+}
diff --git a/views/new_templ.go b/views/new_templ.go
new file mode 100644
index 0000000..53f60ed
--- /dev/null
+++ b/views/new_templ.go
@@ -0,0 +1,271 @@
+// Code generated by templ - DO NOT EDIT.
+
+// templ: version: v0.2.747
+package views
+
+//lint:file-ignore SA4006 This context is only used if a nested component is present.
+
+import "github.com/a-h/templ"
+import templruntime "github.com/a-h/templ/runtime"
+
+import (
+ "fmt"
+ "gitrepo.ru/neonxp/gorum/models"
+ "gitrepo.ru/neonxp/gorum/utils"
+ "strconv"
+)
+
+func NewPost(parent *models.Node) templ.Component {
+ return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
+ templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
+ templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
+ if !templ_7745c5c3_IsBuffer {
+ defer func() {
+ templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err == nil {
+ templ_7745c5c3_Err = templ_7745c5c3_BufErr
+ }
+ }()
+ }
+ ctx = templ.InitializeContext(ctx)
+ templ_7745c5c3_Var1 := templ.GetChildren(ctx)
+ if templ_7745c5c3_Var1 == nil {
+ templ_7745c5c3_Var1 = templ.NopComponent
+ }
+ ctx = templ.ClearChildren(ctx)
+ templ_7745c5c3_Var2 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
+ templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
+ templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
+ if !templ_7745c5c3_IsBuffer {
+ defer func() {
+ templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err == nil {
+ templ_7745c5c3_Err = templ_7745c5c3_BufErr
+ }
+ }()
+ }
+ ctx = templ.InitializeContext(ctx)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<article><header class=\"post-header\"><span>")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var3 string
+ templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(parent.Author.Username)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/new.templ`, Line: 15, Col: 29}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</span> <span>")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var4 string
+ templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(utils.FormatDate(parent.CreatedAt))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/new.templ`, Line: 18, Col: 41}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</span></header>")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = templ.Raw(utils.MarkdownToHTML(parent.Text)).Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</article>")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = NewPostForm(parent).Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ return templ_7745c5c3_Err
+ })
+ templ_7745c5c3_Err = Layout(parent.Parent).Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ return templ_7745c5c3_Err
+ })
+}
+
+func NewTopic(parent *models.Node) templ.Component {
+ return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
+ templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
+ templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
+ if !templ_7745c5c3_IsBuffer {
+ defer func() {
+ templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err == nil {
+ templ_7745c5c3_Err = templ_7745c5c3_BufErr
+ }
+ }()
+ }
+ ctx = templ.InitializeContext(ctx)
+ templ_7745c5c3_Var5 := templ.GetChildren(ctx)
+ if templ_7745c5c3_Var5 == nil {
+ templ_7745c5c3_Var5 = templ.NopComponent
+ }
+ ctx = templ.ClearChildren(ctx)
+ templ_7745c5c3_Var6 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
+ templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
+ templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
+ if !templ_7745c5c3_IsBuffer {
+ defer func() {
+ templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err == nil {
+ templ_7745c5c3_Err = templ_7745c5c3_BufErr
+ }
+ }()
+ }
+ ctx = templ.InitializeContext(ctx)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<h1>")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var7 string
+ templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(parent.Text)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/new.templ`, Line: 28, Col: 18}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</h1>")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = NewTopicForm(parent).Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ return templ_7745c5c3_Err
+ })
+ templ_7745c5c3_Err = Layout(parent.Parent).Render(templ.WithChildren(ctx, templ_7745c5c3_Var6), templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ return templ_7745c5c3_Err
+ })
+}
+
+func NewPostForm(parent *models.Node) templ.Component {
+ return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
+ templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
+ templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
+ if !templ_7745c5c3_IsBuffer {
+ defer func() {
+ templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err == nil {
+ templ_7745c5c3_Err = templ_7745c5c3_BufErr
+ }
+ }()
+ }
+ ctx = templ.InitializeContext(ctx)
+ templ_7745c5c3_Var8 := templ.GetChildren(ctx)
+ if templ_7745c5c3_Var8 == nil {
+ templ_7745c5c3_Var8 = templ.NopComponent
+ }
+ ctx = templ.ClearChildren(ctx)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<form method=\"post\" action=\"")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var9 templ.SafeURL = templ.URL(fmt.Sprintf("/p/%d/new", parent.ID))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var9)))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = CSRF().Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<input type=\"hidden\" name=\"type\" value=\"")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var10 string
+ templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(int(models.PostType)))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/new.templ`, Line: 36, Col: 77}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"> <label for=\"text\"><strong>Ответ</strong></label> <textarea name=\"text\" id=\"text\" placeholder=\"текст...\" rows=\"5\"></textarea> <input type=\"submit\" value=\"Создать\"></form>")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ return templ_7745c5c3_Err
+ })
+}
+
+func NewTopicForm(parent *models.Node) templ.Component {
+ return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
+ templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
+ templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
+ if !templ_7745c5c3_IsBuffer {
+ defer func() {
+ templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err == nil {
+ templ_7745c5c3_Err = templ_7745c5c3_BufErr
+ }
+ }()
+ }
+ ctx = templ.InitializeContext(ctx)
+ templ_7745c5c3_Var11 := templ.GetChildren(ctx)
+ if templ_7745c5c3_Var11 == nil {
+ templ_7745c5c3_Var11 = templ.NopComponent
+ }
+ ctx = templ.ClearChildren(ctx)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<form method=\"post\" action=\"")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var12 templ.SafeURL = templ.URL(fmt.Sprintf("/t/%d/new", parent.ID))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var12)))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = CSRF().Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<input type=\"hidden\" name=\"type\" value=\"")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var13 string
+ templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(int(models.TopicType)))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/new.templ`, Line: 46, Col: 78}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"> <label for=\"text\"><strong>Новая тема</strong></label> <input type=\"text\" name=\"text\" id=\"text\" placeholder=\"название темы...\"> <input type=\"submit\" value=\"Создать\"></form>")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ return templ_7745c5c3_Err
+ })
+}
diff --git a/views/nodes.templ b/views/nodes.templ
index c9baf2e..e6a120c 100644
--- a/views/nodes.templ
+++ b/views/nodes.templ
@@ -4,44 +4,46 @@ import (
"fmt"
"gitrepo.ru/neonxp/gorum/models"
"gitrepo.ru/neonxp/gorum/utils"
+ "strconv"
)
-templ Node(node *models.Node, nodes []*models.Node, count int) {
- @Layout() {
- <h1>{ node.Text }</h1>
- <table>
- <thead>
- <tr>
- <th>Тема</th>
- <th>Дата</th>
- <th>Автор</th>
- </tr>
- </thead>
- <tbody>
- for _, n := range nodes {
- if n.Type == models.TopicType {
- @Topic(n)
- }
- }
- if len(nodes) == 0 {
+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>
- <td colspan="3">
- <strong>Тем нет</strong>
- </td>
+ <th>Тема</th>
+ <th>Тем/Ответов</th>
+ <th>Дата</th>
+ <th>Автор</th>
</tr>
- }
- </tbody>
- </table>
+ </thead>
+ <tbody>
+ for _, n := range topics {
+ @Topic(n)
+ }
+ </tbody>
+ </table>
+ }
if len(nodes) == 0 {
<strong>Постов нет</strong>
}
for _, n := range nodes {
- if n.Type == models.PostType {
- @Post(n)
- }
+ @Post(n, level(node), true)
}
if isAuthorized(ctx) {
- @NewNode(node)
+ @NewPostForm(node)
} else {
<a href="/login">Войдите</a> чтобы ответить в тему.
}
@@ -51,7 +53,10 @@ templ Node(node *models.Node, nodes []*models.Node, count int) {
templ Topic(n *models.Node) {
<tr>
<td>
- <a href={ templ.URL(fmt.Sprintf("/n/%d", n.ID)) }>{ n.Text }</a>
+ <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) }
@@ -62,21 +67,33 @@ templ Topic(n *models.Node) {
</tr>
}
-templ Post(n *models.Node) {
- <article id={ fmt.Sprintf("post%d", n.ID) }>
+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>Пост</span>
<span>
{ n.Author.Username }
- в
+ </span>
+ <span>
{ utils.FormatDate(n.CreatedAt) }
- <a
- href={ templ.URL(fmt.Sprintf("/n/%d#post%d", n.ParentID, n.ID)) }
- >
- #
- </a>
</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
+}
diff --git a/views/nodes_templ.go b/views/nodes_templ.go
index 0424f57..fc23258 100644
--- a/views/nodes_templ.go
+++ b/views/nodes_templ.go
@@ -12,9 +12,10 @@ import (
"fmt"
"gitrepo.ru/neonxp/gorum/models"
"gitrepo.ru/neonxp/gorum/utils"
+ "strconv"
)
-func Node(node *models.Node, nodes []*models.Node, count int) templ.Component {
+func Node(node *models.Node, topics []*models.Node, nodes []*models.Node) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
@@ -44,73 +45,98 @@ func Node(node *models.Node, nodes []*models.Node, count int) templ.Component {
}()
}
ctx = templ.InitializeContext(ctx)
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1)
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
- var templ_7745c5c3_Var3 string
- templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(node.Text)
- if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/nodes.templ`, Line: 11, Col: 17}
- }
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
+ switch node.Type {
+ case models.TopicType:
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<h1>")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var3 string
+ templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(node.Text)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/nodes.templ`, Line: 14, Col: 19}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</h1><div><a href=\"")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var4 templ.SafeURL = templ.URL(fmt.Sprintf("/t/%d/new", node.ID))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var4)))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">Новая подтема</a></div>")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ case models.PostType:
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<h1>Пост</h1>")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ templ_7745c5c3_Err = Post(node, 0, false).Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
}
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- for _, n := range nodes {
- if n.Type == models.TopicType {
+ if len(topics) != 0 {
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<table><thead><tr><th>Тема</th><th>Тем/Ответов</th><th>Дата</th><th>Автор</th></tr></thead> <tbody>")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ for _, n := range topics {
templ_7745c5c3_Err = Topic(n).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
- }
- if len(nodes) == 0 {
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 3)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</tbody></table>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 4)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if len(nodes) == 0 {
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 5)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<strong>Постов нет</strong> ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
for _, n := range nodes {
- if n.Type == models.PostType {
- templ_7745c5c3_Err = Post(n).Render(ctx, templ_7745c5c3_Buffer)
- if templ_7745c5c3_Err != nil {
- return templ_7745c5c3_Err
- }
+ templ_7745c5c3_Err = Post(n, level(node), true).Render(ctx, templ_7745c5c3_Buffer)
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
}
}
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 6)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if isAuthorized(ctx) {
- templ_7745c5c3_Err = NewNode(node).Render(ctx, templ_7745c5c3_Buffer)
+ templ_7745c5c3_Err = NewPostForm(node).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else {
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 7)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<a href=\"/login\">Войдите</a> чтобы ответить в тему.")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
return templ_7745c5c3_Err
})
- templ_7745c5c3_Err = Layout().Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer)
+ templ_7745c5c3_Err = Layout(node.Parent).Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -131,60 +157,73 @@ func Topic(n *models.Node) templ.Component {
}()
}
ctx = templ.InitializeContext(ctx)
- templ_7745c5c3_Var4 := templ.GetChildren(ctx)
- if templ_7745c5c3_Var4 == nil {
- templ_7745c5c3_Var4 = templ.NopComponent
+ templ_7745c5c3_Var5 := templ.GetChildren(ctx)
+ if templ_7745c5c3_Var5 == nil {
+ templ_7745c5c3_Var5 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 8)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<tr><td><a href=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var5 templ.SafeURL = templ.URL(fmt.Sprintf("/n/%d", n.ID))
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var5)))
+ var templ_7745c5c3_Var6 templ.SafeURL = templ.URL(fmt.Sprintf("/t/%d", n.ID))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var6)))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 9)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var6 string
- templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(n.Text)
+ var templ_7745c5c3_Var7 string
+ templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(n.Text)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/nodes.templ`, Line: 54, Col: 61}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/nodes.templ`, Line: 56, Col: 61}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 10)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</a></td><td>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var7 string
- templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(utils.FormatDate(n.CreatedAt))
+ var templ_7745c5c3_Var8 string
+ templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(len(n.Children)))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/nodes.templ`, Line: 57, Col: 34}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/nodes.templ`, Line: 59, Col: 34}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 11)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var8 string
- templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(n.Author.Username)
+ var templ_7745c5c3_Var9 string
+ templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(utils.FormatDate(n.CreatedAt))
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/nodes.templ`, Line: 60, Col: 22}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/nodes.templ`, Line: 62, Col: 34}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var10 string
+ templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(n.Author.Username)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/nodes.templ`, Line: 65, Col: 22}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 12)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td></tr>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -192,7 +231,17 @@ func Topic(n *models.Node) templ.Component {
})
}
-func Post(n *models.Node) templ.Component {
+func levelStyle(level int) templ.CSSClass {
+ templ_7745c5c3_CSSBuilder := templruntime.GetBuilder()
+ templ_7745c5c3_CSSBuilder.WriteString(string(templ.SanitizeCSS(`margin-left`, fmt.Sprintf("%dem", level))))
+ templ_7745c5c3_CSSID := templ.CSSID(`levelStyle`, templ_7745c5c3_CSSBuilder.String())
+ return templ.ComponentCSSClass{
+ ID: templ_7745c5c3_CSSID,
+ Class: templ.SafeCSS(`.` + templ_7745c5c3_CSSID + `{` + templ_7745c5c3_CSSBuilder.String() + `}`),
+ }
+}
+
+func Post(n *models.Node, level int, withFooter bool) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
@@ -205,60 +254,69 @@ func Post(n *models.Node) templ.Component {
}()
}
ctx = templ.InitializeContext(ctx)
- templ_7745c5c3_Var9 := templ.GetChildren(ctx)
- if templ_7745c5c3_Var9 == nil {
- templ_7745c5c3_Var9 = templ.NopComponent
+ templ_7745c5c3_Var11 := templ.GetChildren(ctx)
+ if templ_7745c5c3_Var11 == nil {
+ templ_7745c5c3_Var11 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 13)
+ var templ_7745c5c3_Var12 = []any{levelStyle(level)}
+ templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var12...)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var10 string
- templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("post%d", n.ID))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<article id=\"")
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/nodes.templ`, Line: 66, Col: 42}
+ return templ_7745c5c3_Err
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
+ var templ_7745c5c3_Var13 string
+ templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("post%d", n.ID))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/nodes.templ`, Line: 75, Col: 42}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 14)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" class=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var11 string
- templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(n.Author.Username)
+ var templ_7745c5c3_Var14 string
+ templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(templ.CSSClasses(templ_7745c5c3_Var12).String())
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/nodes.templ`, Line: 70, Col: 23}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/nodes.templ`, Line: 1, Col: 0}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 15)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"><header class=\"post-header\"><span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var12 string
- templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(utils.FormatDate(n.CreatedAt))
+ var templ_7745c5c3_Var15 string
+ templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(n.Author.Username)
if templ_7745c5c3_Err != nil {
- return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/nodes.templ`, Line: 72, Col: 35}
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/nodes.templ`, Line: 78, Col: 23}
}
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 16)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</span> <span>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- var templ_7745c5c3_Var13 templ.SafeURL = templ.URL(fmt.Sprintf("/n/%d#post%d", n.ParentID, n.ID))
- _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var13)))
+ var templ_7745c5c3_Var16 string
+ templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(utils.FormatDate(n.CreatedAt))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/nodes.templ`, Line: 81, Col: 35}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 17)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</span></header>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -266,10 +324,54 @@ func Post(n *models.Node) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 18)
+ if withFooter {
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<footer class=\"post-header\"><a href=\"")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var17 templ.SafeURL = templ.URL(fmt.Sprintf("/p/%d/new", n.ID))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var17)))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">Ответить</a> <a href=\"")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var18 templ.SafeURL = templ.URL(fmt.Sprintf("/p/%d", n.ID))
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var18)))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">Ответов: ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var19 string
+ templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(len(n.Children)))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/nodes.templ`, Line: 88, Col: 101}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</a></footer>")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</article>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return templ_7745c5c3_Err
})
}
+
+func level(node *models.Node) int {
+ if node.Type == models.PostType {
+ return 1
+ }
+ return 0
+}
diff --git a/views/nodes_templ.txt b/views/nodes_templ.txt
deleted file mode 100644
index 99b0698..0000000
--- a/views/nodes_templ.txt
+++ /dev/null
@@ -1,18 +0,0 @@
-<h1>
-</h1><table><thead><tr><th>Тема</th><th>Дата</th><th>Автор</th></tr></thead> <tbody>
-<tr><td colspan=\"3\"><strong>Тем нет</strong></td></tr>
-</tbody></table>
-<strong>Постов нет</strong>
-
-<a href=\"/login\">Войдите</a> чтобы ответить в тему.
-<tr><td><a href=\"
-\">
-</a></td><td>
-</td><td>
-</td></tr>
-<article id=\"
-\"><header class=\"post-header\"><span>Пост</span> <span>
- в
- <a href=\"
-\">#</a></span></header>
-</article>
diff --git a/views/register.templ b/views/register.templ
index 9974110..0a4384e 100644
--- a/views/register.templ
+++ b/views/register.templ
@@ -1,7 +1,7 @@
package views
templ Register(username, email string) {
- @Layout() {
+ @Layout(nil) {
<h1>Регистрация</h1>
<form method="post">
<label for="username">Имя пользователя:</label>
diff --git a/views/register_templ.go b/views/register_templ.go
index 184ef44..5008775 100644
--- a/views/register_templ.go
+++ b/views/register_templ.go
@@ -38,7 +38,7 @@ func Register(username, email string) templ.Component {
}()
}
ctx = templ.InitializeContext(ctx)
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<h1>Регистрация</h1><form method=\"post\"><label for=\"username\">Имя пользователя:</label> <input type=\"text\" id=\"username\" name=\"username\" required=\"true\" placeholder=\"имя пользователя\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -51,7 +51,7 @@ func Register(username, email string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"> <label for=\"email\">Электропочта:</label> <input type=\"email\" id=\"email\" name=\"email\" required=\"true\" placeholder=\"имя@mail.ru\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -64,13 +64,13 @@ func Register(username, email string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
- templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 3)
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"> <label for=\"password\">Пароль:</label> <input type=\"password\" id=\"password\" name=\"password\" required=\"true\" placeholder=\"пароль\"> <label for=\"password2\">Повторите пароль:</label> <input type=\"password\" id=\"password2\" name=\"password2\" required=\"true\" placeholder=\"повторите пароль\"> <input type=\"submit\" value=\"Регистрация\"></form>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return templ_7745c5c3_Err
})
- templ_7745c5c3_Err = Layout().Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer)
+ templ_7745c5c3_Err = Layout(nil).Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
diff --git a/views/register_templ.txt b/views/register_templ.txt
deleted file mode 100644
index a0d2d34..0000000
--- a/views/register_templ.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-<h1>Регистрация</h1><form method=\"post\"><label for=\"username\">Имя пользователя:</label> <input type=\"text\" id=\"username\" name=\"username\" required=\"true\" placeholder=\"имя пользователя\" value=\"
-\"> <label for=\"email\">Электропочта:</label> <input type=\"email\" id=\"email\" name=\"email\" required=\"true\" placeholder=\"имя@mail.ru\" value=\"
-\"> <label for=\"password\">Пароль:</label> <input type=\"password\" id=\"password\" name=\"password\" required=\"true\" placeholder=\"пароль\"> <label for=\"password2\">Повторите пароль:</label> <input type=\"password\" id=\"password2\" name=\"password2\" required=\"true\" placeholder=\"повторите пароль\"> <input type=\"submit\" value=\"Регистрация\"></form>