aboutsummaryrefslogtreecommitdiff
path: root/cgi
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2025-10-06 12:20:44 +0100
committerNat Lasseter <user@4574.co.uk>2025-10-06 12:20:44 +0100
commit43348a5c05da435a9969a62c0406e945c070a6ae (patch)
treed109c8f321884a4914919f90d7f086bb54f932c4 /cgi
parent85ec671d07834d97e63526daa2f962e358c732b7 (diff)
Three shelves
Diffstat (limited to 'cgi')
-rw-r--r--cgi/whisky-shelf.cgi17
1 files changed, 13 insertions, 4 deletions
diff --git a/cgi/whisky-shelf.cgi b/cgi/whisky-shelf.cgi
index 668be4b..b27220b 100644
--- a/cgi/whisky-shelf.cgi
+++ b/cgi/whisky-shelf.cgi
@@ -1,9 +1,11 @@
require "json"
-def shelf_contents(data)
- data.map { |bottle|
+def shelf_contents(data, filter)
+ data.select { |bottle|
+ bottle["status"] == filter
+ }.map { |bottle|
$cgi.div(class: "bottle") {
- $cgi.h3 { bottle["name"] } +
+ $cgi.h4 { bottle["name"] } +
$cgi.img(class: "bottle",
src: "shelf/#{bottle["image"]}")
}
@@ -15,7 +17,14 @@ data = JSON.parse(File.read("../inc/shelf.json"))
$page =
$cgi.div {
$cgi.h2 { "What's on my shelf?" } +
- $cgi.div { shelf_contents(data) }
+ $cgi.div {
+ $cgi.h3 { "Open" } +
+ shelf_contents(data, "open") +
+ $cgi.h3 { "Unopened" } +
+ shelf_contents(data, "new") +
+ $cgi.h3 { "Finished" } +
+ shelf_contents(data, "gone")
+ }
}
# vim: set filetype=ruby: