diff --git a/src/main/scala/app/WikiController.scala b/src/main/scala/app/WikiController.scala index e31a1ee..1edf66b 100644 --- a/src/main/scala/app/WikiController.scala +++ b/src/main/scala/app/WikiController.scala @@ -8,7 +8,9 @@ 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)) } } \ No newline at end of file diff --git a/src/main/scala/util/WikiUtil.scala b/src/main/scala/util/WikiUtil.scala index 5620687..2f4c28b 100644 --- a/src/main/scala/util/WikiUtil.scala +++ b/src/main/scala/util/WikiUtil.scala @@ -13,8 +13,10 @@ * * @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 @@ 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 @@ 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. diff --git a/src/main/scala/view/helpers.scala b/src/main/scala/view/helpers.scala index 6088628..6a3b1b3 100644 --- a/src/main/scala/view/helpers.scala +++ b/src/main/scala/view/helpers.scala @@ -18,6 +18,12 @@ def format(value: String): twirl.api.Html = twirl.api.Html( value.replaceAll(" ", " ").replaceAll("\t", "    ").replaceAll("\n", "
")) + 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. */ diff --git a/src/main/twirl/wiki.scala.html b/src/main/twirl/wiki.scala.html index f138263..9530d16 100644 --- a/src/main/twirl/wiki.scala.html +++ b/src/main/twirl/wiki.scala.html @@ -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) - xxxx + @page.map { page => +

@pageName

+
+ @helpers.markdown(page.content) +
+
+ Last Edited by @page.committer at @helpers.datetime(page.time) +
+ } } \ No newline at end of file