diff --git a/app/views/problems/import.html.haml b/app/views/problems/import.html.haml --- a/app/views/problems/import.html.haml +++ b/app/views/problems/import.html.haml @@ -22,8 +22,17 @@ %span{:class => 'help'} Leave blank to use the same value as the name above. %tr %td Testdata file: + %td= file_field_tag 'file' + %tr %td - = file_field_tag 'file' + %td + %span{:class => 'help'} + In .zip, .tgz, tar.gz, .tar format. + It should includes inputs (e.g., 1.in, 2a.in, 2b.in) + and solutions (e.g., 1.sol, 2a.sol, 2b.sol). + %br/ + You may put task description in *.html for raw html + and *.md or *.markdown for markdown. %tr %td %td diff --git a/app/views/tasks/_problem.html.erb b/app/views/tasks/_problem.html.erb --- a/app/views/tasks/_problem.html.erb +++ b/app/views/tasks/_problem.html.erb @@ -11,9 +11,7 @@ <% if problem.description.markdowned %> <%= markdown(problem.description.body) %> <% else %> -
<%= problem.description.body %> -<% end %> <% else %> (not available) diff --git a/lib/testdata_importer.rb b/lib/testdata_importer.rb --- a/lib/testdata_importer.rb +++ b/lib/testdata_importer.rb @@ -31,6 +31,9 @@ @log_msg = "Importing test pair failed. (0 test pairs imported)" end end + + @log_msg << import_problem_description(dirname) + return true end @@ -106,4 +109,26 @@ return test_num > 1 end + def import_problem_description(dirname) + html_files = Dir["#{dirname}/*.html"] + markdown_files = Dir["#{dirname}/*.md"] + Dir["#{dirname}/*.markdown"] + if (html_files.length != 0) or (markdown_files.length != 0) + description = @problem.description || Description.new + + if html_files.length != 0 + filename = html_files[0] + description.markdowned = false + else + filename = markdown_files[0] + description.markdowned = true + end + + description.body = open(filename).read + description.save + @problem.description = description + @problem.save + return "\nProblem description imported from #{filename}." + end + end + end