From 562451fa5dbb9b9ad35fb37ebf528726db474a9c Mon Sep 17 00:00:00 2001 From: Guillaume Dott Date: Tue, 9 Dec 2014 12:38:12 +0100 Subject: [PATCH] Add route to list available data files --- nikoli.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/nikoli.rb b/nikoli.rb index 698cf2d..751b947 100755 --- a/nikoli.rb +++ b/nikoli.rb @@ -23,9 +23,16 @@ GAMES.each do |game| get("/#{game}.js") { coffee game } end +get "/data/:game.json" do |game| + data_file = Pathname.new(File.join(settings.data_folder, game)) + halt(404) unless data_file.directory? + + json data_file.children(false).map { |path| path.to_s.sub(/.yml$/, '') } +end + get "/data/:game/:file.json" do |game, file| - data_file = File.join(settings.data_folder, game, "#{file}.yml") + data_file = File.expand_path(File.join(settings.data_folder, game, "#{file}.yml")) halt(404) unless File.exist?(data_file) - json YAML.load_file(data_file).sample + json YAML.load_file(data_file)['data'].sample end