mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 14:05:52 +01:00
Implementing Wiki part.
This commit is contained in:
@@ -8,7 +8,9 @@ class WikiController extends ControllerBase {
|
||||
val owner = params("owner")
|
||||
val repository = params("repository")
|
||||
|
||||
html.wiki(WikiUtil.getPage(owner, repository, "Home"), JGitUtil.getRepositoryInfo(owner, repository, servletContext))
|
||||
html.wiki("Home",
|
||||
WikiUtil.getPage(owner, repository, "Home"),
|
||||
JGitUtil.getRepositoryInfo(owner, repository, servletContext))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,8 +13,10 @@ object WikiUtil {
|
||||
*
|
||||
* @param name the page name
|
||||
* @param content the page content
|
||||
* @param committer the last committer
|
||||
* @param time the last modified time
|
||||
*/
|
||||
case class WikiPageInfo(name: String, content: String)
|
||||
case class WikiPageInfo(name: String, content: String, committer: String, time: Date)
|
||||
|
||||
/**
|
||||
* The model for wiki page history.
|
||||
@@ -44,6 +46,7 @@ object WikiUtil {
|
||||
if(!dir.exists){
|
||||
val repo = new RepositoryBuilder().setGitDir(dir).setBare.build
|
||||
repo.create
|
||||
savePage(owner, repository, "Home", "Welcome to the %s wiki!!".format(repository), owner, "Initial Commit")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,8 +57,8 @@ object WikiUtil {
|
||||
createWikiRepository(owner, repository)
|
||||
val git = Git.open(getWikiRepositoryDir(owner, repository))
|
||||
try {
|
||||
JGitUtil.getFileList(git, "master", ".").find(_.name == pageName).map { file =>
|
||||
WikiPageInfo(file.name, new String(git.getRepository.open(file.id).getBytes, "UTF-8"))
|
||||
JGitUtil.getFileList(git, "master", ".").find(_.name == pageName + ".md").map { file =>
|
||||
WikiPageInfo(file.name, new String(git.getRepository.open(file.id).getBytes, "UTF-8"), file.committer, file.time)
|
||||
}
|
||||
} catch {
|
||||
// TODO no commit, but it should not judge by exception.
|
||||
|
||||
@@ -18,6 +18,12 @@ object helpers {
|
||||
def format(value: String): twirl.api.Html = twirl.api.Html(
|
||||
value.replaceAll(" ", " ").replaceAll("\t", " ").replaceAll("\n", "<br>"))
|
||||
|
||||
def markdown(value: String): twirl.api.Html = {
|
||||
import org.pegdown._
|
||||
val html = new PegDownProcessor().markdownToHtml(value)
|
||||
twirl.api.Html(html)
|
||||
}
|
||||
|
||||
/**
|
||||
* Cut the given string by specified length.
|
||||
*/
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
@(page: Option[util.WikiUtil.WikiPageInfo], repository: app.RepositoryInfo)(implicit context: app.Context)
|
||||
@main("Wiki"){
|
||||
@(pageName: String, page: Option[util.WikiUtil.WikiPageInfo], repository: app.RepositoryInfo)(implicit context: app.Context)
|
||||
@import view.helpers
|
||||
@main(pageName + " - " + repository.owner + "/" + repository.name){
|
||||
@header("wiki", repository)
|
||||
<ul class="nav nav-tabs">
|
||||
<li><a href="">Home</a></li>
|
||||
<li class="active"><a href="">Home</a></li>
|
||||
<li><a href="">Pages</a></li>
|
||||
<li><a href="">Wiki History</a></li>
|
||||
<li><a href="">Git Access</a></li>
|
||||
</ul>
|
||||
xxxx
|
||||
@page.map { page =>
|
||||
<h1 class="wiki-title">@pageName</h1>
|
||||
<div class="markdown-body">
|
||||
@helpers.markdown(page.content)
|
||||
</div>
|
||||
<div class="small">
|
||||
<span class="description">Last Edited by @page.committer at @helpers.datetime(page.time)</span>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user