nikoli/nikoli.rb

32 lines
683 B
Ruby
Raw Normal View History

2014-12-05 12:52:12 +01:00
#!/usr/bin/env ruby
require 'sinatra'
2014-12-05 17:27:23 +01:00
require 'sinatra/content_for'
require 'sinatra/json'
2014-12-05 17:27:23 +01:00
require 'yaml'
2014-12-05 12:52:12 +01:00
require 'coffee-script'
require 'slim'
require 'sass'
2014-12-08 17:48:22 +01:00
GAMES = %i{hitori nurikabe sudoku}
2014-12-08 12:32:01 +01:00
set :data_folder, File.expand_path('./data')
2014-12-05 12:52:12 +01:00
get('/application.css') { scss :application }
get('/application.js') { coffee :application }
2014-12-05 12:52:12 +01:00
2014-12-08 12:32:01 +01:00
get('/') { slim :index, locals: {games: GAMES} }
2014-12-05 12:52:12 +01:00
2014-12-08 12:32:01 +01:00
GAMES.each do |game|
2014-12-05 12:52:12 +01:00
get("/#{game}") { slim game }
get("/#{game}.js") { coffee game }
end
get "/data/:game/:file.json" do |game, file|
data_file = File.join(settings.data_folder, game, "#{file}.yml")
halt(404) unless File.exist?(data_file)
json YAML.load_file(data_file).sample
end