diff --git a/src/main/scala/app/RepositoryViewerController.scala b/src/main/scala/app/RepositoryViewerController.scala index 6b8d6ea..375fd84 100644 --- a/src/main/scala/app/RepositoryViewerController.scala +++ b/src/main/scala/app/RepositoryViewerController.scala @@ -93,33 +93,25 @@ treeWalk.setRecursive(true) getPathObjectId(path, treeWalk) } map { objectId => -// if(raw){ -// // Download -// defining(JGitUtil.getContentFromId(git, objectId, false).get){ bytes => -// contentType = FileUtil.getContentType(path, bytes) -// bytes -// } -// } else { - // Viewer - val large = FileUtil.isLarge(git.getRepository.getObjectDatabase.open(objectId).getSize) - val viewer = if(FileUtil.isImage(path)) "image" else if(large) "large" else "other" - val bytes = if(viewer == "other") JGitUtil.getContentFromId(git, objectId, false) else None + // Viewer + val large = FileUtil.isLarge(git.getRepository.getObjectDatabase.open(objectId).getSize) + val viewer = if(FileUtil.isImage(path)) "image" else if(large) "large" else "other" + val bytes = if(viewer == "other") JGitUtil.getContentFromId(git, objectId, false) else None - val content = if(viewer == "other"){ - if(bytes.isDefined && FileUtil.isText(bytes.get)){ - // text - JGitUtil.ContentInfo("text", bytes.map(StringUtil.convertFromByteArray)) - } else { - // binary - JGitUtil.ContentInfo("binary", None) - } + val content = if(viewer == "other"){ + if(bytes.isDefined && FileUtil.isText(bytes.get)){ + // text + JGitUtil.ContentInfo("text", bytes.map(StringUtil.convertFromByteArray)) } else { - // image or large - JGitUtil.ContentInfo(viewer, None) + // binary + JGitUtil.ContentInfo("binary", None) } + } else { + // image or large + JGitUtil.ContentInfo(viewer, None) + } - repo.html.editor(id, repository, path.split("/").toList, content, new JGitUtil.CommitInfo(revCommit)) -// } + repo.html.editor(id, repository, path.split("/").toList, content, new JGitUtil.CommitInfo(revCommit)) } getOrElse NotFound } }) diff --git a/src/main/scala/view/helpers.scala b/src/main/scala/view/helpers.scala index 891bd05..a20a6b3 100644 --- a/src/main/scala/view/helpers.scala +++ b/src/main/scala/view/helpers.scala @@ -164,6 +164,45 @@ 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(".tcl")) => "tcl" + case x if(x.endsWith(".yml")) => "yaml" + case _ => "plain_text" + } + } + + /** * Implicit conversion to add mkHtml() to Seq[Html]. */ implicit class RichHtmlSeq(seq: Seq[Html]) { diff --git a/src/main/twirl/repo/blob.scala.html b/src/main/twirl/repo/blob.scala.html index acb193a..42ab0cc 100644 --- a/src/main/twirl/repo/blob.scala.html +++ b/src/main/twirl/repo/blob.scala.html @@ -29,6 +29,7 @@
diff --git a/src/main/twirl/repo/editor.scala.html b/src/main/twirl/repo/editor.scala.html index e1c2251..7061176 100644 --- a/src/main/twirl/repo/editor.scala.html +++ b/src/main/twirl/repo/editor.scala.html @@ -20,43 +20,54 @@ -
-
- @avatar(latestCommit, 20)
- @user(latestCommit.committer, latestCommit.mailAddress, "username strong")
- @datetime(latestCommit.time)
-
+ |
-
---|
- @content.content.get
- |
-