aboutsummaryrefslogtreecommitdiff
path: root/cgi/whisky-shelf.cgi
blob: b27220ba23a1e34ae142813bd1318a620937f3e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require "json"

def shelf_contents(data, filter)
  data.select { |bottle|
    bottle["status"] == filter
  }.map { |bottle|
    $cgi.div(class: "bottle") { 
      $cgi.h4 { 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 { 
      $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: