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.
180 lines
4.6 KiB
180 lines
4.6 KiB
require "roda"
|
|
|
|
require_relative "rank_king"
|
|
|
|
module RankKing
|
|
class Web < Roda
|
|
plugin :named_templates
|
|
plugin :public
|
|
plugin :render
|
|
plugin :symbol_views
|
|
|
|
template(:layout) { <<~ERB }
|
|
<!DOCTYPE html>
|
|
<html lang="en-US">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=1" />
|
|
|
|
<link rel="stylesheet" href="/static/main.css">
|
|
|
|
<!-- TODO
|
|
<link rel="icon" sizes="16x16 32x32 48x48" type="image/png" href="/icon.png" />
|
|
<link rel="apple-touch-icon" sizes="180x180" href="/images/icon.png" />
|
|
<link rel="mask-icon" href="/images/icon.svg" color="#000000" />
|
|
-->
|
|
|
|
<title><%= ["Rank King", @page_title].compact.join(" - ") %></title>
|
|
</head>
|
|
<body>
|
|
<main>
|
|
<header>
|
|
<a href="/"><h1>Rank King</h1></a>
|
|
<nav><!-- TODO --></nav>
|
|
</header>
|
|
<%= yield %>
|
|
</main>
|
|
</body>
|
|
</html>
|
|
ERB
|
|
|
|
template(:pools) { <<~ERB }
|
|
<section>
|
|
<h1>Pools</h1>
|
|
<ul>
|
|
<% @pools.each do |pool| %>
|
|
<li><a href="/pools/<%= pool.id %>"><%= pool.name %></a></li>
|
|
<% end %>
|
|
</ul>
|
|
</section>
|
|
ERB
|
|
|
|
template(:pool) { <<~ERB }
|
|
<section>
|
|
<h1><%= @pool.name %></h1>
|
|
|
|
<h2>Axes</h2>
|
|
<ul>
|
|
<% @pool.axes.each do |axis| %>
|
|
<li><a href="/pools/<%= @pool.id %>/axes/<%= axis.id %>"><%= axis.name %></a></li>
|
|
<% end %>
|
|
</ul>
|
|
|
|
<h2>Items</h2>
|
|
<ol>
|
|
<% @pool.items.each do |item| %>
|
|
<li><%= item.title %></li>
|
|
<% end %>
|
|
</ol>
|
|
</section>
|
|
ERB
|
|
|
|
template(:axis) { <<~ERB }
|
|
<section>
|
|
<h1><%= @axis.pool.name %> - <%= @axis.name %></h1>
|
|
|
|
<h2>Items</h2>
|
|
|
|
<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>
|
|
|
|
<form method="post" action="/pools/<%= @pool.id %>/axes/<%= @axis.id %>/rank">
|
|
<% @game.each.with_index do |item, i| %>
|
|
<label><input type="radio" name="winner" value="<%= item.id %>"><%= item.title %></label>
|
|
<input type="hidden" name="item_<%= i %>" value="<%= item.id %>">
|
|
<% end %>
|
|
<input type="submit">
|
|
</form>
|
|
</section>
|
|
ERB
|
|
|
|
template(:theme) { <<~ERB }
|
|
<section>
|
|
<div class="surface-samples">
|
|
<div class="surface1">1</div>
|
|
<div class="surface2">2</div>
|
|
<div class="surface3">3</div>
|
|
<div class="surface4">4</div>
|
|
</div>
|
|
</section>
|
|
<section>
|
|
<div class="text-samples">
|
|
<h1 class="text1">
|
|
<span class="swatch accent"></span>
|
|
Accent
|
|
</h1>
|
|
<h1 class="text1">
|
|
<span class="swatch text1"></span>
|
|
Text Color 1
|
|
</h1>
|
|
<h1 class="text2">
|
|
<span class="swatch text2"></span>
|
|
Text Color 2
|
|
</h1>
|
|
<br>
|
|
<p class="text1">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
|
|
<p class="text2">Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
|
|
</div>
|
|
</section>
|
|
ERB
|
|
|
|
route do |r|
|
|
r.on "static" do
|
|
r.public
|
|
end
|
|
|
|
r.root do
|
|
r.redirect "/pools"
|
|
end
|
|
|
|
r.on "pools" do
|
|
r.is do
|
|
@pools = Pool.all
|
|
:pools
|
|
end
|
|
|
|
r.on Integer do |id|
|
|
@pool = Pool[id]
|
|
|
|
r.is do
|
|
:pool
|
|
end
|
|
|
|
r.on "axes" do
|
|
r.on Integer do |id|
|
|
@axis = Axis[id]
|
|
|
|
r.is "rank" do
|
|
items = r.params.values_at("item_0", "item_1").map { Item[_1] }
|
|
winner, loser = items.partition { _1.id == r.params.fetch("winner").to_i }.flatten
|
|
RankKing.rank(@axis, winner:, loser:)
|
|
|
|
r.redirect "/pools/#{@pool.id}/axes/#{@axis.id}"
|
|
end
|
|
|
|
r.is do
|
|
@game = RankKing.suggest_game(@axis).shuffle
|
|
|
|
:axis
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
r.is "theme" do
|
|
:theme
|
|
end
|
|
end
|
|
end
|
|
end
|