Description:
add syntax highlighter for submission view using Rouge gem
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r420:2693b87c015f - - 5 files changed: 25 inserted, 8 deleted

@@ -1,56 +1,58
1 source 'https://rubygems.org'
1 source 'https://rubygems.org'
2
2
3 gem 'rails', '3.2.19'
3 gem 'rails', '3.2.19'
4
4
5 # Bundle edge Rails instead:
5 # Bundle edge Rails instead:
6 # gem 'rails', :git => 'git://github.com/rails/rails.git'
6 # gem 'rails', :git => 'git://github.com/rails/rails.git'
7
7
8 gem 'mysql2'
8 gem 'mysql2'
9
9
10 # Gems used only for assets and not required
10 # Gems used only for assets and not required
11 # in production environments by default.
11 # in production environments by default.
12 group :assets do
12 group :assets do
13 gem 'sass-rails', '~> 3.2.3'
13 gem 'sass-rails', '~> 3.2.3'
14 gem 'coffee-rails', '~> 3.2.1'
14 gem 'coffee-rails', '~> 3.2.1'
15
15
16 # See https://github.com/sstephenson/execjs#readme for more supported runtimes
16 # See https://github.com/sstephenson/execjs#readme for more supported runtimes
17 # gem 'therubyracer', :platforms => :ruby
17 # gem 'therubyracer', :platforms => :ruby
18
18
19 gem 'uglifier', '>= 1.0.3'
19 gem 'uglifier', '>= 1.0.3'
20 end
20 end
21
21
22 gem 'prototype-rails'
22 gem 'prototype-rails'
23
23
24 # To use ActiveModel has_secure_password
24 # To use ActiveModel has_secure_password
25 # gem 'bcrypt-ruby', '~> 3.0.0'
25 # gem 'bcrypt-ruby', '~> 3.0.0'
26
26
27 # To use Jbuilder templates for JSON
27 # To use Jbuilder templates for JSON
28 # gem 'jbuilder'
28 # gem 'jbuilder'
29
29
30 # Use unicorn as the app server
30 # Use unicorn as the app server
31 # gem 'unicorn'
31 # gem 'unicorn'
32
32
33 # Deploy with Capistrano
33 # Deploy with Capistrano
34 # gem 'capistrano'
34 # gem 'capistrano'
35
35
36 # To use debugger
36 # To use debugger
37 # gem 'debugger'
37 # gem 'debugger'
38 #
38 #
39
39
40 gem 'jquery-rails'
40 gem 'jquery-rails'
41 gem 'jquery-ui-sass-rails'
41 gem 'jquery-ui-sass-rails'
42 gem 'jquery-timepicker-addon-rails'
42 gem 'jquery-timepicker-addon-rails'
43
43
44 + #syntax highlighter
45 + gem 'rouge'
44
46
45 gem "haml"
47 gem "haml"
46 gem "mail"
48 gem "mail"
47 gem "rdiscount"
49 gem "rdiscount"
48 gem "test-unit"
50 gem "test-unit"
49 gem 'will_paginate', '~> 3.0.0'
51 gem 'will_paginate', '~> 3.0.0'
50 gem 'dynamic_form'
52 gem 'dynamic_form'
51 gem 'in_place_editing'
53 gem 'in_place_editing'
52 gem 'verification', :git => 'git://github.com/sikachu/verification.git'
54 gem 'verification', :git => 'git://github.com/sikachu/verification.git'
53
55
54 group :test, :development do
56 group :test, :development do
55 gem "rspec-rails", "~> 2.0"
57 gem "rspec-rails", "~> 2.0"
56 end
58 end
@@ -59,108 +59,110
59 railties (>= 3.0, < 5.0)
59 railties (>= 3.0, < 5.0)
60 thor (>= 0.14, < 2.0)
60 thor (>= 0.14, < 2.0)
61 jquery-timepicker-addon-rails (1.4.1)
61 jquery-timepicker-addon-rails (1.4.1)
62 railties (>= 3.1)
62 railties (>= 3.1)
63 jquery-ui-rails (4.0.3)
63 jquery-ui-rails (4.0.3)
64 jquery-rails
64 jquery-rails
65 railties (>= 3.1.0)
65 railties (>= 3.1.0)
66 jquery-ui-sass-rails (4.0.3.0)
66 jquery-ui-sass-rails (4.0.3.0)
67 jquery-rails
67 jquery-rails
68 jquery-ui-rails (= 4.0.3)
68 jquery-ui-rails (= 4.0.3)
69 railties (>= 3.1.0)
69 railties (>= 3.1.0)
70 json (1.8.1)
70 json (1.8.1)
71 mail (2.5.4)
71 mail (2.5.4)
72 mime-types (~> 1.16)
72 mime-types (~> 1.16)
73 treetop (~> 1.4.8)
73 treetop (~> 1.4.8)
74 mime-types (1.25.1)
74 mime-types (1.25.1)
75 multi_json (1.10.1)
75 multi_json (1.10.1)
76 mysql2 (0.3.16)
76 mysql2 (0.3.16)
77 polyglot (0.3.5)
77 polyglot (0.3.5)
78 power_assert (0.1.3)
78 power_assert (0.1.3)
79 prototype-rails (3.2.1)
79 prototype-rails (3.2.1)
80 rails (~> 3.2)
80 rails (~> 3.2)
81 rack (1.4.5)
81 rack (1.4.5)
82 rack-cache (1.2)
82 rack-cache (1.2)
83 rack (>= 0.4)
83 rack (>= 0.4)
84 rack-ssl (1.3.4)
84 rack-ssl (1.3.4)
85 rack
85 rack
86 rack-test (0.6.2)
86 rack-test (0.6.2)
87 rack (>= 1.0)
87 rack (>= 1.0)
88 rails (3.2.19)
88 rails (3.2.19)
89 actionmailer (= 3.2.19)
89 actionmailer (= 3.2.19)
90 actionpack (= 3.2.19)
90 actionpack (= 3.2.19)
91 activerecord (= 3.2.19)
91 activerecord (= 3.2.19)
92 activeresource (= 3.2.19)
92 activeresource (= 3.2.19)
93 activesupport (= 3.2.19)
93 activesupport (= 3.2.19)
94 bundler (~> 1.0)
94 bundler (~> 1.0)
95 railties (= 3.2.19)
95 railties (= 3.2.19)
96 railties (3.2.19)
96 railties (3.2.19)
97 actionpack (= 3.2.19)
97 actionpack (= 3.2.19)
98 activesupport (= 3.2.19)
98 activesupport (= 3.2.19)
99 rack-ssl (~> 1.3.2)
99 rack-ssl (~> 1.3.2)
100 rake (>= 0.8.7)
100 rake (>= 0.8.7)
101 rdoc (~> 3.4)
101 rdoc (~> 3.4)
102 thor (>= 0.14.6, < 2.0)
102 thor (>= 0.14.6, < 2.0)
103 rake (10.3.2)
103 rake (10.3.2)
104 rdiscount (2.1.7.1)
104 rdiscount (2.1.7.1)
105 rdoc (3.12.2)
105 rdoc (3.12.2)
106 json (~> 1.4)
106 json (~> 1.4)
107 + rouge (1.6.2)
107 rspec-collection_matchers (1.0.0)
108 rspec-collection_matchers (1.0.0)
108 rspec-expectations (>= 2.99.0.beta1)
109 rspec-expectations (>= 2.99.0.beta1)
109 rspec-core (2.99.2)
110 rspec-core (2.99.2)
110 rspec-expectations (2.99.2)
111 rspec-expectations (2.99.2)
111 diff-lcs (>= 1.1.3, < 2.0)
112 diff-lcs (>= 1.1.3, < 2.0)
112 rspec-mocks (2.99.2)
113 rspec-mocks (2.99.2)
113 rspec-rails (2.99.0)
114 rspec-rails (2.99.0)
114 actionpack (>= 3.0)
115 actionpack (>= 3.0)
115 activemodel (>= 3.0)
116 activemodel (>= 3.0)
116 activesupport (>= 3.0)
117 activesupport (>= 3.0)
117 railties (>= 3.0)
118 railties (>= 3.0)
118 rspec-collection_matchers
119 rspec-collection_matchers
119 rspec-core (~> 2.99.0)
120 rspec-core (~> 2.99.0)
120 rspec-expectations (~> 2.99.0)
121 rspec-expectations (~> 2.99.0)
121 rspec-mocks (~> 2.99.0)
122 rspec-mocks (~> 2.99.0)
122 sass (3.4.1)
123 sass (3.4.1)
123 sass-rails (3.2.6)
124 sass-rails (3.2.6)
124 railties (~> 3.2.0)
125 railties (~> 3.2.0)
125 sass (>= 3.1.10)
126 sass (>= 3.1.10)
126 tilt (~> 1.3)
127 tilt (~> 1.3)
127 sprockets (2.2.2)
128 sprockets (2.2.2)
128 hike (~> 1.2)
129 hike (~> 1.2)
129 multi_json (~> 1.0)
130 multi_json (~> 1.0)
130 rack (~> 1.0)
131 rack (~> 1.0)
131 tilt (~> 1.1, != 1.3.0)
132 tilt (~> 1.1, != 1.3.0)
132 test-unit (3.0.1)
133 test-unit (3.0.1)
133 power_assert
134 power_assert
134 thor (0.19.1)
135 thor (0.19.1)
135 tilt (1.4.1)
136 tilt (1.4.1)
136 treetop (1.4.15)
137 treetop (1.4.15)
137 polyglot
138 polyglot
138 polyglot (>= 0.3.1)
139 polyglot (>= 0.3.1)
139 tzinfo (0.3.41)
140 tzinfo (0.3.41)
140 uglifier (2.5.3)
141 uglifier (2.5.3)
141 execjs (>= 0.3.0)
142 execjs (>= 0.3.0)
142 json (>= 1.8.0)
143 json (>= 1.8.0)
143 will_paginate (3.0.7)
144 will_paginate (3.0.7)
144
145
145 PLATFORMS
146 PLATFORMS
146 ruby
147 ruby
147
148
148 DEPENDENCIES
149 DEPENDENCIES
149 coffee-rails (~> 3.2.1)
150 coffee-rails (~> 3.2.1)
150 dynamic_form
151 dynamic_form
151 haml
152 haml
152 in_place_editing
153 in_place_editing
153 jquery-rails
154 jquery-rails
154 jquery-timepicker-addon-rails
155 jquery-timepicker-addon-rails
155 jquery-ui-sass-rails
156 jquery-ui-sass-rails
156 mail
157 mail
157 mysql2
158 mysql2
158 prototype-rails
159 prototype-rails
159 rails (= 3.2.19)
160 rails (= 3.2.19)
160 rdiscount
161 rdiscount
162 + rouge
161 rspec-rails (~> 2.0)
163 rspec-rails (~> 2.0)
162 sass-rails (~> 3.2.3)
164 sass-rails (~> 3.2.3)
163 test-unit
165 test-unit
164 uglifier (>= 1.0.3)
166 uglifier (>= 1.0.3)
165 verification!
167 verification!
166 will_paginate (~> 3.0.0)
168 will_paginate (~> 3.0.0)
@@ -18,79 +18,91
18 @stalled_processes = GraderProcess.find_stalled_process
18 @stalled_processes = GraderProcess.find_stalled_process
19
19
20 @terminated_processes = GraderProcess.find_terminated_graders
20 @terminated_processes = GraderProcess.find_terminated_graders
21
21
22 @last_task = Task.find(:first,
22 @last_task = Task.find(:first,
23 :order => 'created_at DESC')
23 :order => 'created_at DESC')
24 @last_test_request = TestRequest.find(:first,
24 @last_test_request = TestRequest.find(:first,
25 :order => 'created_at DESC')
25 :order => 'created_at DESC')
26 end
26 end
27
27
28 def clear
28 def clear
29 grader_proc = GraderProcess.find(params[:id])
29 grader_proc = GraderProcess.find(params[:id])
30 grader_proc.destroy if grader_proc!=nil
30 grader_proc.destroy if grader_proc!=nil
31 redirect_to :action => 'list'
31 redirect_to :action => 'list'
32 end
32 end
33
33
34 def clear_terminated
34 def clear_terminated
35 GraderProcess.find_terminated_graders.each do |p|
35 GraderProcess.find_terminated_graders.each do |p|
36 p.destroy
36 p.destroy
37 end
37 end
38 redirect_to :action => 'list'
38 redirect_to :action => 'list'
39 end
39 end
40
40
41 def clear_all
41 def clear_all
42 GraderProcess.find(:all).each do |p|
42 GraderProcess.find(:all).each do |p|
43 p.destroy
43 p.destroy
44 end
44 end
45 redirect_to :action => 'list'
45 redirect_to :action => 'list'
46 end
46 end
47
47
48 def view
48 def view
49 if params[:type]=='Task'
49 if params[:type]=='Task'
50 redirect_to :action => 'task', :id => params[:id]
50 redirect_to :action => 'task', :id => params[:id]
51 else
51 else
52 redirect_to :action => 'test_request', :id => params[:id]
52 redirect_to :action => 'test_request', :id => params[:id]
53 end
53 end
54 end
54 end
55
55
56 def test_request
56 def test_request
57 @test_request = TestRequest.find(params[:id])
57 @test_request = TestRequest.find(params[:id])
58 end
58 end
59
59
60 def task
60 def task
61 @task = Task.find(params[:id])
61 @task = Task.find(params[:id])
62 end
62 end
63
63
64 def submission
64 def submission
65 @submission = Submission.find(params[:id])
65 @submission = Submission.find(params[:id])
66 + formatter = Rouge::Formatters::HTML.new(css_class: 'highlight', line_numbers: true )
67 + lexer = case @submission.language.name
68 + when "c" then Rouge::Lexers::C.new
69 + when "cpp" then Rouge::Lexers::Cpp.new
70 + when "pas" then Rouge::Lexers::Pas.new
71 + when "ruby" then Rouge::Lexers::Ruby.new
72 + when "python" then Rouge::Lexers::Python.new
73 + when "java" then Rouge::Lexers::Java.new
74 + end
75 + @formatted_code = formatter.format(lexer.lex(@submission.source))
76 + @css_style = Rouge::Themes::ThankfulEyes.render(scope: '.highlight')
77 +
66 end
78 end
67
79
68 # various grader controls
80 # various grader controls
69
81
70 def stop
82 def stop
71 grader_proc = GraderProcess.find(params[:id])
83 grader_proc = GraderProcess.find(params[:id])
72 GraderScript.stop_grader(grader_proc.pid)
84 GraderScript.stop_grader(grader_proc.pid)
73 flash[:notice] = 'Grader stopped. It may not disappear now, but it should disappear shortly.'
85 flash[:notice] = 'Grader stopped. It may not disappear now, but it should disappear shortly.'
74 redirect_to :action => 'list'
86 redirect_to :action => 'list'
75 end
87 end
76
88
77 def stop_all
89 def stop_all
78 GraderScript.stop_graders(GraderProcess.find_running_graders +
90 GraderScript.stop_graders(GraderProcess.find_running_graders +
79 GraderProcess.find_stalled_process)
91 GraderProcess.find_stalled_process)
80 flash[:notice] = 'Graders stopped. They may not disappear now, but they should disappear shortly.'
92 flash[:notice] = 'Graders stopped. They may not disappear now, but they should disappear shortly.'
81 redirect_to :action => 'list'
93 redirect_to :action => 'list'
82 end
94 end
83
95
84 def start_grading
96 def start_grading
85 GraderScript.start_grader('grading')
97 GraderScript.start_grader('grading')
86 flash[:notice] = '2 graders in grading env started, one for grading queue tasks, another for grading test request'
98 flash[:notice] = '2 graders in grading env started, one for grading queue tasks, another for grading test request'
87 redirect_to :action => 'list'
99 redirect_to :action => 'list'
88 end
100 end
89
101
90 def start_exam
102 def start_exam
91 GraderScript.start_grader('exam')
103 GraderScript.start_grader('exam')
92 flash[:notice] = '2 graders in grading env started, one for grading queue tasks, another for grading test request'
104 flash[:notice] = '2 graders in grading env started, one for grading queue tasks, another for grading test request'
93 redirect_to :action => 'list'
105 redirect_to :action => 'list'
94 end
106 end
95
107
96 end
108 end
@@ -1,22 +1,27
1 + %style{type: "text/css"}
2 + = @css_style
3 +
1 %h1= "Submission: #{@submission.id}"
4 %h1= "Submission: #{@submission.id}"
2
5
3 %p
6 %p
4 User:
7 User:
5 = "#{@submission.user.login}"
8 = "#{@submission.user.login}"
6 %br/
9 %br/
7 Problem:
10 Problem:
8 - if @submission.problem!=nil
11 - if @submission.problem!=nil
9 = "#{@submission.problem.full_name}"
12 = "#{@submission.problem.full_name}"
10 - else
13 - else
11 = "(n/a)"
14 = "(n/a)"
12 %br/
15 %br/
13 = "Number: #{@submission.number}"
16 = "Number: #{@submission.number}"
14 %br/
17 %br/
15 = "Submitted at: #{format_short_time(@submission.submitted_at)}"
18 = "Submitted at: #{format_short_time(@submission.submitted_at)}"
19 + %br/
20 + = "Points : #{@submission.points}/#{@submission.problem.full_score}"
21 + %br/
22 + = "Comment : #{@submission.grader_comment}"
16
23
17 %b Source code (first 10kb)
24 %b Source code (first 10kb)
18 - %div{:style => "border: 1px solid black; background: lightgrey"}
25 + //%div.highlight{:style => "border: 1px solid black;"}
19 - - if @submission.source
26 + =@formatted_code.html_safe
20 - %pre
21 - =h truncate @submission.source, :length => 10240
22
27
@@ -1,41 +1,37
1 - content_for :header do
1 - content_for :header do
2 = javascript_include_tag 'new'
2 = javascript_include_tag 'new'
3
3
4 %script{:type=>"text/javascript"}
4 %script{:type=>"text/javascript"}
5 $(function () {
5 $(function () {
6 $('#since_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} );
6 $('#since_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} );
7 $('#until_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} );
7 $('#until_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} );
8 });
8 });
9
9
10 -
11 %h1 Login status
10 %h1 Login status
12
11
13 -
14 -
15 -
16 =render partial: 'report_menu'
12 =render partial: 'report_menu'
17 =render partial: 'date_range', locals: {param_text: 'Submission date range:', title: 'Query submission stat in the range' }
13 =render partial: 'date_range', locals: {param_text: 'Submission date range:', title: 'Query submission stat in the range' }
18
14
19 %table.info
15 %table.info
20 %thead
16 %thead
21 %tr.info-head
17 %tr.info-head
22 %th login
18 %th login
23 %th full name
19 %th full name
24 %th total submissions
20 %th total submissions
25 %th submissions
21 %th submissions
26 %tbody
22 %tbody
27 - @submissions.each do |user_id,data|
23 - @submissions.each do |user_id,data|
28 %tr{class: cycle('info-even','info-odd')}
24 %tr{class: cycle('info-even','info-odd')}
29 %td= data[:login]
25 %td= data[:login]
30 %td= data[:full_name]
26 %td= data[:full_name]
31 %td= data[:count]
27 %td= data[:count]
32 %td
28 %td
33 - data[:sub].each do |prob_id,sub_data|
29 - data[:sub].each do |prob_id,sub_data|
34 = "#{sub_data[:prob_name]}: ["
30 = "#{sub_data[:prob_name]}: ["
35 - st = []
31 - st = []
36 - sub_data[:sub_ids].each do |id|
32 - sub_data[:sub_ids].each do |id|
37 - st << link_to(id, controller: 'graders' , action: 'submission', id: id)
33 - st << link_to(id, controller: 'graders' , action: 'submission', id: id)
38 = raw st.join ', '
34 = raw st.join ', '
39 = ']'
35 = ']'
40 %br/
36 %br/
41
37
You need to be logged in to leave comments. Login now