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

1 year ago
require "roda"
1 year ago
require_relative "rank_king"
1 year ago
module RankKing
class Web < Roda
plugin :named_templates
10 months ago
plugin :public
1 year ago
plugin :render
10 months ago
plugin :symbol_views
1 year ago
template(:layout) { <<~ERB }
10 months ago
<!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>
1 year ago
<body>
10 months ago
<main>
<header>
<a href="/"><h1>Rank King</h1></a>
<nav><!-- TODO --></nav>
</header>
<%= yield %>
</main>
1 year ago
</body>
</html>
ERB
template(:pools) { <<~ERB }
10 months ago
<section>
<h1>Pools</h1>
<ul>
<% @pools.each do |pool| %>
<li><a href="/pools/<%= pool.id %>"><%= pool.name %></a></li>
<% end %>
</ul>
</section>
1 year ago
ERB
template(:pool) { <<~ERB }
10 months ago
<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>
1 year ago
ERB
template(:axis) { <<~ERB }
10 months ago
<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>
1 year ago
<% end %>
10 months ago
</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>
1 year ago
ERB
route do |r|
10 months ago
r.on "static" do
r.public
end
1 year ago
r.root do
r.redirect "/pools"
end
r.on "pools" do
r.is do
@pools = Pool.all
10 months ago
:pools
1 year ago
end
r.on Integer do |id|
@pool = Pool[id]
r.is do
10 months ago
:pool
1 year ago
end
r.on "axes" do
1 year ago
r.on Integer do |id|
1 year ago
@axis = Axis[id]
1 year ago
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
10 months ago
:axis
1 year ago
end
1 year ago
end
end
end
end
10 months ago
r.is "theme" do
:theme
end
1 year ago
end
end
end