require "json" def shelf_contents(data) data.map { |bottle| $cgi.div(class: "shelf") { $cgi.h3 { bottle["name"] } + $cgi.img(class: "bottle", src: "shelf/#{bottle["image"]}") } }.join end data = JSON.parse(File.read("../inc/shelf.json")) $page = $cgi.div { $cgi.h2 { "What's on my shelf?" } + $cgi.div { shelf_contents(data) } } # vim: set filetype=ruby: