From 43348a5c05da435a9969a62c0406e945c070a6ae Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Mon, 6 Oct 2025 12:20:44 +0100 Subject: Three shelves --- cgi/whisky-shelf.cgi | 17 +++++++++++++---- inc/shelf.json | 22 +++++++++++----------- 2 files changed, 24 insertions(+), 15 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: diff --git a/inc/shelf.json b/inc/shelf.json index 4a6491a..f5787d1 100644 --- a/inc/shelf.json +++ b/inc/shelf.json @@ -2,56 +2,56 @@ { "name": "Elements of Islay Cask Edit", "image": "eoicaskedit.jpg", - "state": "open" + "status": "open" }, { "name": "Ardbeg Eureka", "image": "ardbegeureka.jpg", - "state": "new" + "status": "new" }, { "name": "Lancaster Spirits 10 Month Old PX", "image": "lancasterpx10mo.jpg", - "state": "new" + "status": "new" }, { "name": "Little Brown Dog Ardmore", "image": "lbdardmore.jpg", - "state": "new" + "status": "new" }, { "name": "Ledaig Sinclair Series Rioja Cask", "image": "ledaigrioja.jpg", - "state": "new" + "status": "new" }, { "name": "Lindores Exclusive Cask", "image": "lindoresexclusive.jpg", - "state": "new" + "status": "new" }, { "name": "Raasay Dun Cana", "image": "raasayduncana.jpg", - "state": "new" + "status": "new" }, { "name": "Springbank 10 Year Old", "image": "springbank10.jpg", - "state": "new" + "status": "new" }, { "name": "Uncharted Whisky Higher Ground", "image": "unchartedhg.jpg", - "state": "new" + "status": "new" }, { "name": "Wormtub 10 Year Old", "image": "wormtub10.jpg", - "state": "new" + "status": "new" }, { "name": "Drago Whiskey 5 Year Old", "image": "drago5yo.jpg", - "state": "new" + "status": "new" } ] -- cgit v1.2.3