Description:
add syntax highlighter for submission view using Rouge gem
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r420:2693b87c015f - - 5 files changed: 25 inserted, 8 deleted
@@ -38,12 +38,14 | |||
|
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' |
@@ -101,12 +101,13 | |||
|
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) |
@@ -155,12 +156,13 | |||
|
155 | 156 | jquery-ui-sass-rails |
|
156 | 157 | |
|
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) |
@@ -60,12 +60,24 | |||
|
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]) |
@@ -1,6 +1,9 | |||
|
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/ |
@@ -10,13 +13,15 | |||
|
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; |
|
|
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 |
@@ -4,18 +4,14 | |||
|
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 |
You need to be logged in to leave comments.
Login now