mirror of
				https://github.com/gitbucket/gitbucket.git
				synced 2025-11-03 20:15:59 +01:00 
			
		
		
		
	Merge pull request #1986 from kounoike/pr-ace-mode-by-js
set ace editor mode by ext-modelist.js
This commit is contained in:
		@@ -316,44 +316,6 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
 | 
			
		||||
   */
 | 
			
		||||
  def isPast(date: Date): Boolean = System.currentTimeMillis > date.getTime
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Returns file type for AceEditor.
 | 
			
		||||
   */
 | 
			
		||||
  def editorType(fileName: String): String = {
 | 
			
		||||
    fileName.toLowerCase match {
 | 
			
		||||
      case x if (x.endsWith(".bat"))     => "batchfile"
 | 
			
		||||
      case x if (x.endsWith(".java"))    => "java"
 | 
			
		||||
      case x if (x.endsWith(".scala"))   => "scala"
 | 
			
		||||
      case x if (x.endsWith(".js"))      => "javascript"
 | 
			
		||||
      case x if (x.endsWith(".css"))     => "css"
 | 
			
		||||
      case x if (x.endsWith(".md"))      => "markdown"
 | 
			
		||||
      case x if (x.endsWith(".html"))    => "html"
 | 
			
		||||
      case x if (x.endsWith(".xml"))     => "xml"
 | 
			
		||||
      case x if (x.endsWith(".c"))       => "c_cpp"
 | 
			
		||||
      case x if (x.endsWith(".cpp"))     => "c_cpp"
 | 
			
		||||
      case x if (x.endsWith(".coffee"))  => "coffee"
 | 
			
		||||
      case x if (x.endsWith(".ejs"))     => "ejs"
 | 
			
		||||
      case x if (x.endsWith(".hs"))      => "haskell"
 | 
			
		||||
      case x if (x.endsWith(".json"))    => "json"
 | 
			
		||||
      case x if (x.endsWith(".jsp"))     => "jsp"
 | 
			
		||||
      case x if (x.endsWith(".jsx"))     => "jsx"
 | 
			
		||||
      case x if (x.endsWith(".cl"))      => "lisp"
 | 
			
		||||
      case x if (x.endsWith(".clojure")) => "lisp"
 | 
			
		||||
      case x if (x.endsWith(".lua"))     => "lua"
 | 
			
		||||
      case x if (x.endsWith(".php"))     => "php"
 | 
			
		||||
      case x if (x.endsWith(".py"))      => "python"
 | 
			
		||||
      case x if (x.endsWith(".rdoc"))    => "rdoc"
 | 
			
		||||
      case x if (x.endsWith(".rhtml"))   => "rhtml"
 | 
			
		||||
      case x if (x.endsWith(".ruby"))    => "ruby"
 | 
			
		||||
      case x if (x.endsWith(".sh"))      => "sh"
 | 
			
		||||
      case x if (x.endsWith(".sql"))     => "sql"
 | 
			
		||||
      case x if (x.endsWith(".tcl"))     => "tcl"
 | 
			
		||||
      case x if (x.endsWith(".vbs"))     => "vbscript"
 | 
			
		||||
      case x if (x.endsWith(".yml"))     => "yaml"
 | 
			
		||||
      case _                             => "plain_text"
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  def pre(value: Html): Html = Html(s"<pre>${value.body.trim.split("\n").map(_.trim).mkString("\n")}</pre>")
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
 
 | 
			
		||||
@@ -75,6 +75,7 @@
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
<script src="@helpers.assets("/vendors/ace/ace.js")" type="text/javascript" charset="utf-8"></script>
 | 
			
		||||
<script src="@helpers.assets("/vendors/ace/ext-modelist.js")" type="text/javascript" charset="utf-8"></script>
 | 
			
		||||
<script type="text/javascript" src="@helpers.assets("/vendors/jsdifflib/difflib.js")"></script>
 | 
			
		||||
<link href="@helpers.assets("/vendors/jsdifflib/diffview.css")" type="text/css" rel="stylesheet" />
 | 
			
		||||
<script>
 | 
			
		||||
@@ -89,7 +90,9 @@ $(function(){
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @if(fileName.isDefined){
 | 
			
		||||
    editor.getSession().setMode("ace/mode/@helpers.editorType(fileName.get)");
 | 
			
		||||
    var modelist = ace.require("ace/ext/modelist");
 | 
			
		||||
    var mode = modelist.getModeForPath("@fileName.get");
 | 
			
		||||
    editor.getSession().setMode(mode.mode);
 | 
			
		||||
  }
 | 
			
		||||
  @if(protectedBranch){
 | 
			
		||||
    editor.setReadOnly(true);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user