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

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