Initial commit
This commit is contained in:
commit
89f483171a
43 changed files with 2245 additions and 0 deletions
59
page.go
Normal file
59
page.go
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
// External
|
||||
we "git.gibonuddevalla.se/go/wrappederror"
|
||||
|
||||
// Standard
|
||||
"fmt"
|
||||
"net/http"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
type Page struct {
|
||||
LAYOUT string
|
||||
PAGE string
|
||||
MENU string
|
||||
Label string
|
||||
Icon string
|
||||
|
||||
Data any
|
||||
}
|
||||
|
||||
func (p *Page) Render(w http.ResponseWriter) {
|
||||
tmpl, err := getPage(p.LAYOUT, p.PAGE)
|
||||
if err != nil {
|
||||
httpError(w, we.Wrap(err).Log())
|
||||
return
|
||||
}
|
||||
|
||||
if p.Icon == "" {
|
||||
p.Icon = p.PAGE
|
||||
}
|
||||
|
||||
if p.Label == "" {
|
||||
r, _ := utf8.DecodeRuneInString(p.PAGE)
|
||||
titled := unicode.ToTitle(r)
|
||||
p.Label = fmt.Sprintf("%s%s", string(titled), p.PAGE[1:len(p.PAGE)])
|
||||
}
|
||||
|
||||
if p.MENU == "" {
|
||||
p.MENU = p.PAGE
|
||||
}
|
||||
|
||||
data := map[string]any{
|
||||
"VERSION": VERSION,
|
||||
"LAYOUT": p.LAYOUT,
|
||||
"PAGE": p.PAGE,
|
||||
"MENU": p.MENU,
|
||||
"Label": p.Label,
|
||||
"Icon": p.Icon,
|
||||
"Data": p.Data,
|
||||
}
|
||||
|
||||
err = tmpl.Execute(w, data)
|
||||
if err != nil {
|
||||
httpError(w, we.Wrap(err).Log())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue