Created
September 8, 2013 21:01
-
-
Save justinj/6488381 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "sinatra" | |
enable :inline_templates | |
def get_algs(input) | |
input | |
.lines | |
.map(&:chomp) | |
.reject(&:empty?) | |
.each_slice(2) | |
.map { |name, alg| [name, alg.split(/\s+or\s+/)] } | |
end | |
def image_for(alg, template) | |
%(<img src="#{template.gsub("$", alg.gsub(/\s/,""))}">) | |
end | |
get "/" do | |
erb :input | |
end | |
post "/create" do | |
erb :algpage, locals: { algs: get_algs(params["input"]), | |
template: params["template"] } | |
end | |
__END__ | |
@@layout | |
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"> | |
<div class="container"> | |
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> | |
<%= yield %> | |
</div> | |
@@input | |
<form action="/create" method="POST"> | |
<label>Template ($ is where your alg will go)</label> | |
<input type="text" name="template" class="form-control" value="http://cube.crider.co.uk/visualcube.php?pzl=2&fmt=gif&size=100&case=$"> | |
<br> | |
<label>Algs, alternating title and alg, algs separated by "or", blank lines ignored</label> | |
<textarea name="input" class="form-control" rows="20" > | |
</textarea> | |
<br> | |
<input type="submit" value="GO!" class="form-control"> | |
</form> | |
@@algpage | |
<table class="table"> | |
<tr> | |
<th>Case</th> | |
<th>Image</th> | |
<th>Alg</th> | |
</tr> | |
<% algs.each do |name, alg| %> | |
<tr> | |
<td><%= name %></td> | |
<td><%= image_for(alg.first, template) %></td> | |
<td><%= alg.join("<br>") %></td> | |
</tr> | |
<% end %> | |
</table> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment