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

@@ -41,6 +41,8
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"
@@ -104,6 +104,7
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)
@@ -158,6 +159,7
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
@@ -63,6 +63,18
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
@@ -1,3 +1,6
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
@@ -13,10 +16,12
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
@@ -7,12 +7,8
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
You need to be logged in to leave comments. Login now