语言条用封装
This commit is contained in:
parent
e694c93d8a
commit
8f37ca1158
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 最高分
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
<script type="text/javascript">
|
||||
var editor_CodeMirror = CodeMirror.fromTextArea(document.getElementById("challenge-answer-edit-small"), {
|
||||
mode: {name: 'text/x-ruby',
|
||||
mode: {name: 'text/x-<%= @language %>',
|
||||
version: 2,
|
||||
singleLineStringErrors: false},
|
||||
lineNumbers: true,
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
var myMirror = $("#game_answer_show")[0];
|
||||
var myCodeMirror = CodeMirror(myMirror, {
|
||||
value: $("#hidden_game_answer").text(),
|
||||
mode: "text/x-java",
|
||||
mode: "text/x-<%= @language %>",
|
||||
readOnly: "nocursor", //只读
|
||||
//cursorBlinkRate: -1, //隐藏光标
|
||||
autofocus: true,
|
||||
|
|
Loading…
Reference in New Issue