You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
1.8 KiB
90 lines
1.8 KiB
require "roda"
|
|
|
|
require_relative "rank_king"
|
|
|
|
module RankKing
|
|
class Web < Roda
|
|
plugin :named_templates
|
|
plugin :render
|
|
|
|
template(:layout) { <<~ERB }
|
|
<html>
|
|
<body>
|
|
<h1>Rank King</h1>
|
|
<%= yield %>
|
|
</body>
|
|
</html>
|
|
ERB
|
|
|
|
template(:pools) { <<~ERB }
|
|
<h2>Pools</h2>
|
|
<ul>
|
|
<% @pools.each do |pool| %>
|
|
<li><a href="/pools/<%= pool.id %>"><%= pool.name %></a></li>
|
|
<% end %>
|
|
</ul>
|
|
ERB
|
|
|
|
template(:pool) { <<~ERB }
|
|
<h2><%= @pool.name %></h2>
|
|
<h3>Axes</h3>
|
|
<ul>
|
|
<% @pool.axes.each do |axis| %>
|
|
<li><a href="/pools/<%= @pool.id %>/axes/<%= axis.id %>"><%= axis.name %></a></li>
|
|
<% end %>
|
|
</ul>
|
|
<h3>Items</h3>
|
|
<ol>
|
|
<% @pool.items.each do |item| %>
|
|
<li><%= item.title %></li>
|
|
<% end %>
|
|
</ol>
|
|
ERB
|
|
|
|
template(:axis) { <<~ERB }
|
|
<h2><%= @axis.pool.name %> - <%= @axis.name %></h2>
|
|
<h3>Items</h3>
|
|
<table>
|
|
<% @axis.ratings.sort_by { -_1.ordinal }.each.with_index do |rating, i| %>
|
|
<tr>
|
|
<td><%= i+1 %></td>
|
|
<td><%= rating.item.title %></td>
|
|
<td><%= rating.ordinal.round(1) %></td>
|
|
<td><%= rating.mu.round(1) %></td>
|
|
<td><%= rating.sigma.round(1) %></td>
|
|
</tr>
|
|
<% end %>
|
|
</table>
|
|
ERB
|
|
|
|
route do |r|
|
|
r.root do
|
|
r.redirect "/pools"
|
|
end
|
|
|
|
r.on "pools" do
|
|
r.is do
|
|
@pools = Pool.all
|
|
view :pools
|
|
end
|
|
|
|
r.on Integer do |id|
|
|
@pool = Pool[id]
|
|
|
|
r.is do
|
|
view :pool
|
|
end
|
|
|
|
r.on "axes" do
|
|
r.is Integer do |id|
|
|
@axis = Axis[id]
|
|
|
|
view :axis
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|