From 8f37ca1158897c8f52d8cf7463549fb69b8435ad Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 31 Mar 2017 10:51:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=AD=E8=A8=80=E6=9D=A1=E7=94=A8=E5=B0=81?= =?UTF-8?q?=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 6 ++++++ app/controllers/games_controller.rb | 2 ++ app/helpers/application_helper.rb | 15 +++++++++++++++ app/views/challenges/_form.html.erb | 2 +- app/views/games/_file_edit_form.html.erb | 2 +- app/views/games/_game_show.html.erb | 2 +- 6 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 314a58d20..7a255cb92 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -6,6 +6,7 @@ class ChallengesController < ApplicationController before_filter :build_challege_from_params, :only => [:new, :create] before_filter :tpi_manager_allowed, :only => [:challenge_build, :destroy, :show, :edit, :new, :create] before_filter :query_challeges, :only => [:show, :edit, :update] + before_filter :find_language, :only => [:show, :new, :edit] include ApplicationHelper @@ -204,4 +205,9 @@ class ChallengesController < ApplicationController render_404 end + def find_language + language = @shixun.language + @language = language_switch language + end + end diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 2862f2695..9d3fd8430 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -26,6 +26,8 @@ class GamesController < ApplicationController @rev = @rev.nil? ? "master" : @rev @git_url = git_repository_url(@myshixun, "Myshixun") @type = params[:type] + language = @shixun.myshixuns.try(:language) + @language = language_switch(language) # 默认打开文件 if @path == "" && !game_path.nil? && !@repository.cat(game_path, @rev).blank? && @type != "root" @path = game_path diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a5f2d6074..81f0090b4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -33,6 +33,21 @@ module ApplicationHelper extend Forwardable def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter + # codeMirror语言转换 + def language_switch language + case language + when "Java" + "text/c-java" + when "C" + "text/x-csrc" + when "C++" + "text/x-c++src" + when "Python" + "text/x-python" + when "Ruby" + "text/x-ruby" + end + end # 定义实训相关方法 # myshixun 最高分 diff --git a/app/views/challenges/_form.html.erb b/app/views/challenges/_form.html.erb index 241e99228..ad9b4983a 100644 --- a/app/views/challenges/_form.html.erb +++ b/app/views/challenges/_form.html.erb @@ -272,7 +272,7 @@ } var editor = CodeMirror.fromTextArea(document.getElementById("challenge_answer"), { - mode: {name: 'text/x-java', + mode: {name: 'text/x-<%= @language %>', version: 2, singleLineStringErrors: false}, lineNumbers: true, diff --git a/app/views/games/_file_edit_form.html.erb b/app/views/games/_file_edit_form.html.erb index 37f76c646..25f74ebf1 100644 --- a/app/views/games/_file_edit_form.html.erb +++ b/app/views/games/_file_edit_form.html.erb @@ -13,7 +13,7 @@