diff --git a/Gemfile b/Gemfile --- a/Gemfile +++ b/Gemfile @@ -41,6 +41,8 @@ gem 'jquery-ui-sass-rails' gem 'jquery-timepicker-addon-rails' +#syntax highlighter +gem 'rouge' gem "haml" gem "mail" diff --git a/Gemfile.lock b/Gemfile.lock --- a/Gemfile.lock +++ b/Gemfile.lock @@ -104,6 +104,7 @@ rdiscount (2.1.7.1) rdoc (3.12.2) json (~> 1.4) + rouge (1.6.2) rspec-collection_matchers (1.0.0) rspec-expectations (>= 2.99.0.beta1) rspec-core (2.99.2) @@ -158,6 +159,7 @@ prototype-rails rails (= 3.2.19) rdiscount + rouge rspec-rails (~> 2.0) sass-rails (~> 3.2.3) test-unit diff --git a/app/controllers/graders_controller.rb b/app/controllers/graders_controller.rb --- a/app/controllers/graders_controller.rb +++ b/app/controllers/graders_controller.rb @@ -63,6 +63,18 @@ def submission @submission = Submission.find(params[:id]) + formatter = Rouge::Formatters::HTML.new(css_class: 'highlight', line_numbers: true ) + lexer = case @submission.language.name + when "c" then Rouge::Lexers::C.new + when "cpp" then Rouge::Lexers::Cpp.new + when "pas" then Rouge::Lexers::Pas.new + when "ruby" then Rouge::Lexers::Ruby.new + when "python" then Rouge::Lexers::Python.new + when "java" then Rouge::Lexers::Java.new + end + @formatted_code = formatter.format(lexer.lex(@submission.source)) + @css_style = Rouge::Themes::ThankfulEyes.render(scope: '.highlight') + end # various grader controls diff --git a/app/views/graders/submission.html.haml b/app/views/graders/submission.html.haml --- a/app/views/graders/submission.html.haml +++ b/app/views/graders/submission.html.haml @@ -1,3 +1,6 @@ +%style{type: "text/css"} + = @css_style + %h1= "Submission: #{@submission.id}" %p @@ -13,10 +16,12 @@ = "Number: #{@submission.number}" %br/ = "Submitted at: #{format_short_time(@submission.submitted_at)}" + %br/ + = "Points : #{@submission.points}/#{@submission.problem.full_score}" + %br/ + = "Comment : #{@submission.grader_comment}" %b Source code (first 10kb) -%div{:style => "border: 1px solid black; background: lightgrey"} - - if @submission.source - %pre - =h truncate @submission.source, :length => 10240 +//%div.highlight{:style => "border: 1px solid black;"} +=@formatted_code.html_safe diff --git a/app/views/report/submission_stat.html.haml b/app/views/report/submission_stat.html.haml --- a/app/views/report/submission_stat.html.haml +++ b/app/views/report/submission_stat.html.haml @@ -7,12 +7,8 @@ $('#until_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} ); }); - %h1 Login status - - - =render partial: 'report_menu' =render partial: 'date_range', locals: {param_text: 'Submission date range:', title: 'Query submission stat in the range' }