diff options
author | Nat Lasseter <user@4574.co.uk> | 2025-10-06 12:20:44 +0100 |
---|---|---|
committer | Nat Lasseter <user@4574.co.uk> | 2025-10-06 12:20:44 +0100 |
commit | 43348a5c05da435a9969a62c0406e945c070a6ae (patch) | |
tree | d109c8f321884a4914919f90d7f086bb54f932c4 /cgi/whisky-shelf.cgi | |
parent | 85ec671d07834d97e63526daa2f962e358c732b7 (diff) |
Three shelves
Diffstat (limited to 'cgi/whisky-shelf.cgi')
-rw-r--r-- | cgi/whisky-shelf.cgi | 17 |
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: |