-
Notifications
You must be signed in to change notification settings - Fork 87
/
app.rb
76 lines (62 loc) · 1.31 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# This is a simple Sinatra app that drives testfirst.org on Heroku
here = File.expand_path(File.dirname(__FILE__))
require 'rubygems'
require 'sinatra'
require 'erector'
require 'json'
$: << "#{here}/lib"
require "code"
require "rspec_code"
$: << "#{here}/web"
require "page"
require "home"
require "about"
require "learn_ruby"
require "learn_javascript"
require "live"
require "course"
set :public_folder, "web"
configure do
mime_type :rb, 'text/plain'
end
get '/' do
Home.new.to_pretty
end
get '/about' do
About.new.to_pretty
end
get '/learn_ruby' do
LearnRuby.new.to_pretty
end
get '/learn_javascript' do
LearnJavaScript.new.to_pretty
end
get '/download/:file' do
send_file("#{here}/download/#{params[:file]}", :disposition => 'attachment', :filename => params[:file])
end
post "/run" do
# p params
if params[:code]
if params[:rspec]
RspecCode.new(params[:code], :rspec => params[:rspec]).run.to_json
else
Code.new(params[:code]).run.to_json
end
else
"need code, was passed #{params.to_json}"
# redirect "/live"
end
end
# todo: test
get "/live/:course/:lab" do
Live.new(
:course => Course.new(params[:course]),
:lab_name => params[:lab]
).to_pretty
end
get "/live" do
Live.new(
:course => Course.new("learn_ruby"),
:lab_name => "hello"
).to_pretty
end