Create a Sinatra app to manage puzzles

master
Guillaume Dott 2014-12-05 12:52:12 +01:00
parent 353ee471b3
commit 6822f56f74
7 changed files with 82 additions and 27 deletions

7
Gemfile 100644
View File

@ -0,0 +1,7 @@
source 'https://rubygems.org'
gem 'sinatra', '~> 1.4'
gem 'slim'
gem 'coffee-script'
gem 'therubyracer'
gem 'sass'

36
Gemfile.lock 100644
View File

@ -0,0 +1,36 @@
GEM
remote: https://rubygems.org/
specs:
coffee-script (2.3.0)
coffee-script-source
execjs
coffee-script-source (1.8.0)
execjs (2.2.2)
libv8 (3.16.14.7)
rack (1.5.2)
rack-protection (1.5.3)
rack
ref (1.0.5)
sass (3.2.19)
sinatra (1.4.5)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
slim (2.1.0)
temple (~> 0.6.9)
tilt (>= 1.3.3, < 2.1)
temple (0.6.10)
therubyracer (0.12.1)
libv8 (~> 3.16.14.0)
ref
tilt (1.4.1)
PLATFORMS
ruby
DEPENDENCIES
coffee-script
sass
sinatra (~> 1.4)
slim
therubyracer

15
nikoli.rb 100755
View File

@ -0,0 +1,15 @@
#!/usr/bin/env ruby
require 'sinatra'
require 'coffee-script'
require 'slim'
require 'sass'
get('/application.css') { scss :application }
get('/') { slim :index }
%i{nurikabe}.each do |game|
get("/#{game}") { slim game }
get("/#{game}.js") { coffee game }
end

View File

@ -1,10 +1,3 @@
<!DOCTYPE html>
<html>
<head>
<title>Nurikabe</title>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=yes" />
<style>
body { body {
background-color: #aaa; background-color: #aaa;
font-family: Verdana,Arial,sans-serif; font-family: Verdana,Arial,sans-serif;
@ -47,23 +40,3 @@ td {
.black { .black {
background-color: #aaa; background-color: #aaa;
} }
</style>
<script type="text/javascript" src="nurikabe.js"></script>
<script type="text/javascript">
var nurikabe;
var game = JSON.parse("[[4,-1,-1,0,2],[0,-1,2,-1,-1],[0,-1,0,-1,3],[0,-1,-1,-1,0],[-1,-1,1,-1,0]]");
document.addEventListener("DOMContentLoaded", function() {
var board = document.getElementById('board');
nurikabe = new Nurikabe(board);
nurikabe.generate(game);
});
</script>
</head>
<body>
<h1>Nurikabe</h1>
<div id="board">
</div>
</body>
</html>

5
views/index.slim 100644
View File

@ -0,0 +1,5 @@
doctype html
html
head
body
h1 Hello world!

View File

@ -0,0 +1,19 @@
doctype html
html
head
title Nurikabe
meta charset="utf-8"
meta name="viewport" content="initial-scale=1.0, user-scalable=yes"
link rel="stylesheet" media="all" href="/application.css"
script type="text/javascript" src="/nurikabe.js"
body
h1 Nurikabe
#board
javascript:
document.addEventListener("DOMContentLoaded", function() {
var game = JSON.parse("[[4,-1,-1,0,2],[0,-1,2,-1,-1],[0,-1,0,-1,3],[0,-1,-1,-1,0],[-1,-1,1,-1,0]]");
nurikabe = new Nurikabe(document.getElementById('board'));
nurikabe.generate(game);
});