From 6822f56f746a8babf7af878f38a8eeea123bb837 Mon Sep 17 00:00:00 2001 From: Guillaume Dott Date: Fri, 5 Dec 2014 12:52:12 +0100 Subject: [PATCH] Create a Sinatra app to manage puzzles --- Gemfile | 7 +++++ Gemfile.lock | 36 ++++++++++++++++++++++++ nikoli.rb | 15 ++++++++++ nurikabe.html => views/application.scss | 27 ------------------ views/index.slim | 5 ++++ nurikabe.coffee => views/nurikabe.coffee | 0 views/nurikabe.slim | 19 +++++++++++++ 7 files changed, 82 insertions(+), 27 deletions(-) create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100755 nikoli.rb rename nurikabe.html => views/application.scss (50%) create mode 100644 views/index.slim rename nurikabe.coffee => views/nurikabe.coffee (100%) create mode 100644 views/nurikabe.slim diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..db6a62d --- /dev/null +++ b/Gemfile @@ -0,0 +1,7 @@ +source 'https://rubygems.org' + +gem 'sinatra', '~> 1.4' +gem 'slim' +gem 'coffee-script' +gem 'therubyracer' +gem 'sass' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..ce22866 --- /dev/null +++ b/Gemfile.lock @@ -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 diff --git a/nikoli.rb b/nikoli.rb new file mode 100755 index 0000000..56eea4b --- /dev/null +++ b/nikoli.rb @@ -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 diff --git a/nurikabe.html b/views/application.scss similarity index 50% rename from nurikabe.html rename to views/application.scss index 7389c8d..5002fe1 100644 --- a/nurikabe.html +++ b/views/application.scss @@ -1,10 +1,3 @@ - - - - Nurikabe - - - - - - - -

Nurikabe

- -
-
- - diff --git a/views/index.slim b/views/index.slim new file mode 100644 index 0000000..081f8f0 --- /dev/null +++ b/views/index.slim @@ -0,0 +1,5 @@ +doctype html +html + head + body + h1 Hello world! diff --git a/nurikabe.coffee b/views/nurikabe.coffee similarity index 100% rename from nurikabe.coffee rename to views/nurikabe.coffee diff --git a/views/nurikabe.slim b/views/nurikabe.slim new file mode 100644 index 0000000..91951ba --- /dev/null +++ b/views/nurikabe.slim @@ -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); + });