aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p@janouch.name>2019-04-15 04:14:32 +0200
committerPřemysl Janouch <p@janouch.name>2019-04-15 10:54:27 +0200
commit0b32fa576fe3317acd260e0980b492bbafd7fd5a (patch)
tree3ba009a6102907b91e6ab86f06008295b15f3036
parent82c6c34ea58ec775a799533c4ce6f497b53d11bf (diff)
downloadsklad-0b32fa576fe3317acd260e0980b492bbafd7fd5a.tar.gz
sklad-0b32fa576fe3317acd260e0980b492bbafd7fd5a.tar.xz
sklad-0b32fa576fe3317acd260e0980b492bbafd7fd5a.zip
sklad: show whole container descriptions
-rw-r--r--cmd/sklad/container.tmpl2
-rw-r--r--cmd/sklad/main.go15
2 files changed, 15 insertions, 2 deletions
diff --git a/cmd/sklad/container.tmpl b/cmd/sklad/container.tmpl
index 147e124..8118baf 100644
--- a/cmd/sklad/container.tmpl
+++ b/cmd/sklad/container.tmpl
@@ -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>
diff --git a/cmd/sklad/main.go b/cmd/sklad/main.go
index 1baa66b..22d25b7 100644
--- a/cmd/sklad/main.go
+++ b/cmd/sklad/main.go
@@ -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)