Browse Source

sklad: show whole container descriptions

master
Přemysl Janouch 1 year ago
parent
commit
0b32fa576f
Signed by: Přemysl Janouch <p@janouch.name> GPG Key ID: A0420B94F92B9493
2 changed files with 15 additions and 2 deletions
  1. +1
    -1
      cmd/sklad/container.tmpl
  2. +14
    -1
      cmd/sklad/main.go

+ 1
- 1
cmd/sklad/container.tmpl View File

@@ -36,7 +36,7 @@
</header>

<form method=post action="container?id={{ .Container.Id }}">
<textarea name=description rows=5>
<textarea name=description rows="{{ max 5 (lines .Container.Description) }}">
{{ .Container.Description }}
</textarea>
<footer>

+ 14
- 1
cmd/sklad/main.go View File

@@ -334,6 +334,18 @@ func handle(w http.ResponseWriter, r *http.Request) {
}
}

var funcMap = template.FuncMap{
"max": func(i, j int) int {
if i > j {
return i
}
return j
},
"lines": func(s string) int {
return strings.Count(s, "\n") + 1
},
}

func main() {
// Randomize the RNG for session string generation.
rand.Seed(time.Now().UnixNano())
@@ -356,7 +368,8 @@ func main() {
log.Fatalln(err)
}
for _, name := range m {
templates[name] = template.Must(template.ParseFiles("base.tmpl", name))
templates[name] = template.Must(template.New("base.tmpl").
Funcs(funcMap).ParseFiles("base.tmpl", name))
}

http.HandleFunc("/", handle)

Loading…
Cancel
Save