-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapplication.rb
47 lines (40 loc) · 1012 Bytes
/
application.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
# The one and only controller.
class GraderApp < Sinatra::Base
get '/' do
@problems = Problem.all
erb :"grdr/form"
end
post '/' do
@problem_name = params[:task]
problem_class = Problem.all.find do |problem|
problem.param_name == @problem_name
end
unless problem_class
status :not_found
return
end
@problem = problem_class.new
@problem.code = params[:code]
if params[:debug] == 'true'
content_type :html
@problem.test_html
else
@problem.upload_test_html
@problem.grade
headers['X-Grader-MaxScore'] = 1.to_s
headers['X-Grader-Score'] = @problem.verdict_score.to_s
headers['X-Grader-Verdict'] = @problem.verdict_reason
erb :"grdr/verdict"
end
end
helpers do
include Rack::Utils
alias_method :h, :escape_html
end
set :erb, trim: '-'
enable :dump_errors, :logging
disable :sessions
end
# Dynamically load problem definitions.
require './lib/problem.rb'
Problem.load_all