Display readme if README.md exists.

This commit is contained in:
takezoe
2013-04-28 03:22:48 +09:00
parent 2336e7864d
commit 5740faf805
2 changed files with 29 additions and 13 deletions

View File

@@ -252,18 +252,7 @@ class RepositoryViewerServlet extends ServletBase {
val dir = getBranchDir(owner, repository, branchName)
val git = Git.open(dir)
val latestRev = {if(path == ".") git.log else git.log.addPath(path)}.call.iterator.next
html.files(
// current branch
branchName,
// repository
getRepositoryInfo(owner, repository),
// current path
if(path == ".") Nil else path.split("/").toList,
// latest commit
CommitInfo(latestRev.getName, latestRev.getCommitterIdent.getWhen, latestRev.getCommitterIdent.getName, latestRev.getShortMessage),
// file list
new File(dir, path).listFiles()
val files = new File(dir, path).listFiles()
.filterNot{ file => file.getName == ".git" }
.sortWith { (file1, file2) => (file1.isDirectory, file2.isDirectory) match {
case (true , false) => true
@@ -279,6 +268,26 @@ class RepositoryViewerServlet extends ServletBase {
}
}
.flatten.toList
// process README.md
val readme = files.find(_.name == "README.md").map { file =>
import org.pegdown._
new PegDownProcessor().markdownToHtml(FileUtils.readFileToString(new File(dir, path + "/" + file.name), "UTF-8"))
}
html.files(
// current branch
branchName,
// repository
getRepositoryInfo(owner, repository),
// current path
if(path == ".") Nil else path.split("/").toList,
// latest commit
CommitInfo(latestRev.getName, latestRev.getCommitterIdent.getWhen, latestRev.getCommitterIdent.getName, latestRev.getShortMessage),
// file list
files,
// readme
readme
)
}

View File

@@ -1,4 +1,4 @@
@(branch: String, repository: app.RepositoryInfo, pathList: List[String], latestCommit: app.CommitInfo, files: List[app.FileInfo])(implicit context: app.Context)
@(branch: String, repository: app.RepositoryInfo, pathList: List[String], latestCommit: app.CommitInfo, files: List[app.FileInfo], readme: Option[String])(implicit context: app.Context)
@import context._
@import view.helpers
@main(repository.owner+"/"+repository.name) {
@@ -52,4 +52,11 @@
</tr>
}
</table>
@readme.map { html =>
<table class="table table-bordered">
<tr>
<td>@Html(html)</td>
</tr>
</table>
}
}