tabbed interface.
This commit is contained in:
parent
e0771c095b
commit
f6ea7a56a9
@ -35,6 +35,8 @@ func pageHandler(w http.ResponseWriter, r *http.Request) {
|
||||
templates.UsageTab(secure, r.URL.Host, username).Render(r.Context(), w)
|
||||
case "downloads.html":
|
||||
templates.DownloadsTab().Render(r.Context(), w)
|
||||
case "sessions.html":
|
||||
templates.SessionsTab().Render(r.Context(), w)
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
|
@ -9,20 +9,9 @@ import (
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type RenderFunc func(secure string, host string, username string) templ.Component
|
||||
type RenderFunc func() templ.Component
|
||||
|
||||
type Params struct {
|
||||
secure string
|
||||
host string
|
||||
username string
|
||||
}
|
||||
|
||||
type Rendering struct {
|
||||
params Params
|
||||
render RenderFunc
|
||||
}
|
||||
|
||||
func render(dir string, name string, params Params, render RenderFunc) {
|
||||
func render(dir string, name string, render RenderFunc) {
|
||||
fname := filepath.Join(dir, name)
|
||||
log.Printf("Writing to %s", fname)
|
||||
f, err := os.Create(fname)
|
||||
@ -31,7 +20,7 @@ func render(dir string, name string, params Params, render RenderFunc) {
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
err = render(params.secure, params.host, params.username).Render(context.Background(), f)
|
||||
err = render().Render(context.Background(), f)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -40,11 +29,15 @@ func render(dir string, name string, params Params, render RenderFunc) {
|
||||
func main() {
|
||||
dir := "html/docs"
|
||||
|
||||
params := Params{
|
||||
secure: "s",
|
||||
host: "example.com",
|
||||
username: "converge",
|
||||
fullindex := func() templ.Component {
|
||||
return templates.Index("s", "example.com", "converge")
|
||||
}
|
||||
usage := func() templ.Component {
|
||||
return templates.UsageTab("s", "example.com", "converge")
|
||||
}
|
||||
|
||||
render(dir, "index.html", params, templates.Index)
|
||||
render(dir, "fullindex.html", fullindex)
|
||||
render(dir, "index.html", templates.AboutTab)
|
||||
render(dir, "usage.html", usage)
|
||||
render(dir, "downloads.html", templates.Downloads)
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ templ About() {
|
||||
|
||||
|
||||
templ AboutTab() {
|
||||
@BasePage() {
|
||||
@BasePage(1) {
|
||||
@About()
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,15 @@
|
||||
package templates
|
||||
|
||||
|
||||
templ BasePage() {
|
||||
func active(actual int, active int) string {
|
||||
res := "nav-item nav-link"
|
||||
if actual == active {
|
||||
return res + " active"
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
templ BasePage(tab int) {
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
@ -19,14 +27,36 @@ templ BasePage() {
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="container">
|
||||
<nav class="navbar navbar-expand-sm navbar-light bg-light">
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
|
||||
data-bs-target="#navbarNavAltMarkup"
|
||||
aria-controls="navbarNav" aria-expanded="false"
|
||||
aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
|
||||
<div class="nav nav-pills">
|
||||
|
||||
<a class={active(1,tab)} href="index.html">overview</a>
|
||||
|
||||
<a class={active(2,tab)} href="usage.html">usage</a>
|
||||
|
||||
<a class={active(3,tab)} href="downloads.html">downloads</a>
|
||||
|
||||
<a class={active(4,tab)} href="sessions.html">sessions</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
{ children... }
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
}
|
1
pkg/templates/constants.go
Normal file
1
pkg/templates/constants.go
Normal file
@ -0,0 +1 @@
|
||||
package templates
|
@ -40,7 +40,7 @@ templ Downloads() {
|
||||
|
||||
|
||||
templ DownloadsTab() {
|
||||
@BasePage() {
|
||||
@BasePage(3) {
|
||||
@Downloads()
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package templates
|
||||
|
||||
templ Index(secure string, host string, username string) {
|
||||
@BasePage() {
|
||||
@BasePage(0) {
|
||||
@About()
|
||||
@Usage(secure, host, username)
|
||||
@Downloads()
|
||||
|
15
pkg/templates/sessions.templ
Normal file
15
pkg/templates/sessions.templ
Normal file
@ -0,0 +1,15 @@
|
||||
package templates
|
||||
|
||||
|
||||
templ Sessions() {
|
||||
<div>
|
||||
To be done
|
||||
</div>
|
||||
}
|
||||
|
||||
|
||||
templ SessionsTab() {
|
||||
@BasePage(4) {
|
||||
@Sessions()
|
||||
}
|
||||
}
|
@ -123,7 +123,7 @@ templ Usage(secure string, host string, username string) {
|
||||
|
||||
|
||||
templ UsageTab(secure string, host string, username string) {
|
||||
@BasePage() {
|
||||
@BasePage(2) {
|
||||
@Usage(secure, host, username)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user