require "json" def shelf_contents(data, filter) $cgi.div { data.select { |bottle| bottle["status"] == filter }.map { |bottle| $cgi.div(class: "bottle") { $cgi.h4 { bottle["name"] } + $cgi.a(href: "shelf/#{bottle["image"]}") { $cgi.img(class: "bottle", src: "shelf/#{bottle["image"]}") } } }.join } end data = JSON.parse(File.read("../inc/shelf.json")) $page = $cgi.h2 { "What's on my shelf?" } + $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: