Add app.Context to transfer implicit data from Servlet to view.

This commit is contained in:
takezoe
2013-04-19 16:26:26 +09:00
parent 9f4d77cef0
commit 7bfa88064d
11 changed files with 54 additions and 42 deletions

View File

@@ -24,7 +24,7 @@ class CreateRepositoryServlet extends ServletBase {
* Show the new repository form. * Show the new repository form.
*/ */
get("/") { get("/") {
html.newrepo.render() html.newrepo()
} }
/** /**

View File

@@ -25,7 +25,7 @@ class RepositoryViewerServlet extends ServletBase {
*/ */
get("/:owner") { get("/:owner") {
val owner = params("owner") val owner = params("owner")
html.user.render(owner, getRepositories(owner).map(getRepositoryInfo(owner, _))) html.user(owner, getRepositories(owner).map(getRepositoryInfo(owner, _)))
} }
/** /**
@@ -85,7 +85,7 @@ class RepositoryViewerServlet extends ServletBase {
} }
} }
html.commits.render(branchName, getRepositoryInfo(owner, repository), html.commits(branchName, getRepositoryInfo(owner, repository),
listBuffer.toSeq.splitWith{ (commit1, commit2) => listBuffer.toSeq.splitWith{ (commit1, commit2) =>
view.helpers.date(commit1.time) == view.helpers.date(commit2.time) view.helpers.date(commit1.time) == view.helpers.date(commit2.time)
}, page, i.hasNext) }, page, i.hasNext)
@@ -108,7 +108,7 @@ class RepositoryViewerServlet extends ServletBase {
val git = Git.open(dir) val git = Git.open(dir)
val latestRev = git.log.addPath(path).call.iterator.next val latestRev = git.log.addPath(path).call.iterator.next
html.blob.render(branchName, getRepositoryInfo(owner, repository), path.split("/").toList, content, html.blob(branchName, getRepositoryInfo(owner, repository), path.split("/").toList, content,
CommitInfo(latestRev.getName, latestRev.getCommitterIdent.getWhen, latestRev.getCommitterIdent.getName, latestRev.getShortMessage)) CommitInfo(latestRev.getName, latestRev.getCommitterIdent.getWhen, latestRev.getCommitterIdent.getName, latestRev.getShortMessage))
} }
@@ -187,7 +187,7 @@ class RepositoryViewerServlet extends ServletBase {
val git = Git.open(dir) val git = Git.open(dir)
val latestRev = {if(path == ".") git.log else git.log.addPath(path)}.call.iterator.next val latestRev = {if(path == ".") git.log else git.log.addPath(path)}.call.iterator.next
html.files.render( html.files(
// current branch // current branch
branchName, branchName,
// repository // repository

View File

@@ -14,6 +14,8 @@ abstract class ServletBase extends ScalatraServlet with JacksonJsonSupport {
implicit val jsonFormats = DefaultFormats implicit val jsonFormats = DefaultFormats
implicit def context: Context = Context(servletContext.getContextPath)
// TODO get from session // TODO get from session
val LoginUser = System.getProperty("user.name") val LoginUser = System.getProperty("user.name")
@@ -43,3 +45,5 @@ abstract class ServletBase extends ScalatraServlet with JacksonJsonSupport {
} }
} }
case class Context(path: String)

View File

@@ -1,14 +1,15 @@
@(branch: String, repository: app.RepositoryInfo, pathList: List[String], content: String, latestCommit: app.CommitInfo) @(branch: String, repository: app.RepositoryInfo, pathList: List[String], content: String, latestCommit: app.CommitInfo)(implicit context: app.Context)
@import context._
@main(repository.owner+"/"+repository.name) { @main(repository.owner+"/"+repository.name) {
@header(branch, repository) @header(branch, repository)
@navtab(branch, repository, "files") @navtab(branch, repository, "files")
<div class="head"> <div class="head">
<a href="/@repository.owner/@repository.name/tree/@branch">@repository.name</a> / <a href="@path/@repository.owner/@repository.name/tree/@branch">@repository.name</a> /
@pathList.zipWithIndex.map { case (path, i) => @pathList.zipWithIndex.map { case (path, i) =>
@if(i == pathList.length - 1){ @if(i == pathList.length - 1){
@path @path
} else { } else {
<a href="/@repository.owner/@repository.name/tree/@branch/@pathList.take(i + 1).mkString("/")">@path</a> / <a href="@path/@repository.owner/@repository.name/tree/@branch/@pathList.take(i + 1).mkString("/")">@path</a> /
} }
} }
</div> </div>
@@ -17,7 +18,7 @@
<tr> <tr>
<th style="font-weight: normal;"> <th style="font-weight: normal;">
<div class="pull-left"> <div class="pull-left">
<a href="/@latestCommit.committer">@latestCommit.committer</a> <a href="@path/@latestCommit.committer">@latestCommit.committer</a>
<span class="description">@view.helpers.datetime(latestCommit.time)</span> <span class="description">@view.helpers.datetime(latestCommit.time)</span>
@view.helpers.cut(latestCommit.message, 100)<br> @view.helpers.cut(latestCommit.message, 100)<br>
</div> </div>
@@ -49,5 +50,5 @@
padding-left: 20px; padding-left: 20px;
} }
</style> </style>
<script src="/assets/google-code-prettify/run_prettify.js"></script> <script src="@path/assets/google-code-prettify/run_prettify.js"></script>
} }

View File

@@ -1,9 +1,10 @@
@(branch: String, repository: app.RepositoryInfo, commits: Seq[Seq[app.CommitInfo]], page: Int, hasNext: Boolean) @(branch: String, repository: app.RepositoryInfo, commits: Seq[Seq[app.CommitInfo]], page: Int, hasNext: Boolean)(implicit context: app.Context)
@import context._
@main(repository.owner+"/"+repository.name) { @main(repository.owner+"/"+repository.name) {
@header(branch, repository) @header(branch, repository)
@navtab(branch, repository, "commits") @navtab(branch, repository, "commits")
<div class="head"> <div class="head">
<a href="/@repository.owner/@repository.name/tree/@branch">@repository.name</a> / Commit History <a href="@path/@repository.owner/@repository.name/tree/@branch">@repository.name</a> / Commit History
</div> </div>
@commits.map { date => @commits.map { date =>
@@ -17,7 +18,7 @@
<div class="pull-left"> <div class="pull-left">
<a href="#"><strong>@view.helpers.cut(commit.message, 100)</strong></a><br> <a href="#"><strong>@view.helpers.cut(commit.message, 100)</strong></a><br>
<div class="small"> <div class="small">
<a href="/@commit.committer">@commit.committer</a> <a href="@path/@commit.committer">@commit.committer</a>
<span class="description">@view.helpers.datetime(commit.time)</span> <span class="description">@view.helpers.datetime(commit.time)</span>
</div> </div>
</div> </div>

View File

@@ -1,11 +1,12 @@
@(branch: String, repository: app.RepositoryInfo, pathList: List[String], latestCommit: app.CommitInfo, files: List[app.FileInfo]) @(branch: String, repository: app.RepositoryInfo, pathList: List[String], latestCommit: app.CommitInfo, files: List[app.FileInfo])(implicit context: app.Context)
@import context._
@main(repository.owner+"/"+repository.name) { @main(repository.owner+"/"+repository.name) {
@header(branch, repository) @header(branch, repository)
@navtab(branch, repository, "files") @navtab(branch, repository, "files")
<div class="head"> <div class="head">
<a href="/@repository.owner/@repository.name/tree/@branch">@repository.name</a> / <a href="@path/@repository.owner/@repository.name/tree/@branch">@repository.name</a> /
@pathList.zipWithIndex.map { case (path, i) => @pathList.zipWithIndex.map { case (path, i) =>
<a href="/@repository.owner/@repository.name/tree/@branch/@pathList.take(i + 1).mkString("/")">@path</a> / <a href="@path/@repository.owner/@repository.name/tree/@branch/@pathList.take(i + 1).mkString("/")">@path</a> /
} }
</div> </div>
<table class="table table-file-list"> <table class="table table-file-list">
@@ -24,7 +25,7 @@
@if(pathList.size > 0){ @if(pathList.size > 0){
<tr> <tr>
<td width="16"></td> <td width="16"></td>
<td><a href="/@repository.owner/@repository.name@if(pathList.size > 1){/tree/@branch/@pathList.init.mkString("/")}">..</a></td> <td><a href="@path/@repository.owner/@repository.name@if(pathList.size > 1){/tree/@branch/@pathList.init.mkString("/")}">..</a></td>
<td></td> <td></td>
<td></td> <td></td>
</tr> </tr>
@@ -33,20 +34,20 @@
<tr> <tr>
<td width="16"> <td width="16">
@if(file.isDirectory){ @if(file.isDirectory){
<img src="/assets/common/images/folder.png"/> <img src="@path/assets/common/images/folder.png"/>
} else { } else {
<img src="/assets/common/images/file.png"/> <img src="@path/assets/common/images/file.png"/>
} }
</td> </td>
<td> <td>
@if(file.isDirectory){ @if(file.isDirectory){
<a href="/@repository.owner/@repository.name/tree@{(branch :: pathList).mkString("/", "/", "/")}@file.name">@file.name</a> <a href="@path/@repository.owner/@repository.name/tree@{(branch :: pathList).mkString("/", "/", "/")}@file.name">@file.name</a>
} else { } else {
<a href="/@repository.owner/@repository.name/blob@{(branch :: pathList).mkString("/", "/", "/")}@file.name">@file.name</a> <a href="@path/@repository.owner/@repository.name/blob@{(branch :: pathList).mkString("/", "/", "/")}@file.name">@file.name</a>
} }
</td> </td>
<td>@view.helpers.datetime(file.time)</td> <td>@view.helpers.datetime(file.time)</td>
<td>@view.helpers.cut(file.message, 60) [<a href="/@file.committer">@file.committer</a>]</td> <td>@view.helpers.cut(file.message, 60) [<a href="@path/@file.committer">@file.committer</a>]</td>
</tr> </tr>
} }
</table> </table>

View File

@@ -1,6 +1,7 @@
@(branch: String, repository: app.RepositoryInfo) @(branch: String, repository: app.RepositoryInfo)(implicit context: app.Context)
@import context._
<div class="head"> <div class="head">
<a href="/@repository.owner">@repository.owner</a> / <a href="/@repository.owner/@repository.name">@repository.name</a> <a href="@path/@repository.owner">@repository.owner</a> / <a href="@path/@repository.owner/@repository.name">@repository.name</a>
</div> </div>
<div class="navbar"> <div class="navbar">
<div class="navbar-inner"> <div class="navbar-inner">

View File

@@ -1,4 +1,5 @@
@(title: String)(body: Html) @(title: String)(body: Html)(implicit context: app.Context)
@import context._
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
@@ -6,16 +7,16 @@
<title>@title - GitBucket</title> <title>@title - GitBucket</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Le styles --> <!-- Le styles -->
<link href="/assets/bootstrap/css/bootstrap.css" rel="stylesheet"> <link href="@path/assets/bootstrap/css/bootstrap.css" rel="stylesheet">
<link href="/assets/bootstrap/css/bootstrap-responsive.css" rel="stylesheet"> <link href="@path/assets/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements --> <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]> <!--[if lt IE 9]>
<script src="/assets/bootstrap/js/html5shiv.js"></script> <script src="@path/assets/bootstrap/js/html5shiv.js"></script>
<![endif]--> <![endif]-->
<link href="/assets/common/css/gitbucket.css" rel="stylesheet"> <link href="@path/assets/common/css/gitbucket.css" rel="stylesheet">
<script src="/assets/common/js/jquery-1.9.1.js"></script> <script src="@path/assets/common/js/jquery-1.9.1.js"></script>
<script src="/assets/common/js/validation.js"></script> <script src="@path/assets/common/js/validation.js"></script>
<script src="/assets/bootstrap/js/bootstrap.js"></script> <script src="@path/assets/bootstrap/js/bootstrap.js"></script>
</head> </head>
<body> <body>
<div class="navbar navbar-inverse"> <div class="navbar navbar-inverse">
@@ -29,7 +30,7 @@
<a class="brand" href="#">GitBucket</a> <a class="brand" href="#">GitBucket</a>
<div class="nav-collapse collapse"> <div class="nav-collapse collapse">
<ul class="nav pull-right"> <ul class="nav pull-right">
<li><a href="/new">New repo</a></li> <li><a href="@path/new">New repo</a></li>
<li><a href="#about">Account</a></li> <li><a href="#about">Account</a></li>
<li><a href="#contact">Sign out</a></li> <li><a href="#contact">Sign out</a></li>
</ul> </ul>

View File

@@ -1,17 +1,18 @@
@(branch: String, repository: app.RepositoryInfo, active: String) @(branch: String, repository: app.RepositoryInfo, active: String)(implicit context: app.Context)
@import context._
<ul class="nav nav-tabs"> <ul class="nav nav-tabs">
<li> <li>
<div class="btn-group" style="margin-right: 20px;"> <div class="btn-group" style="margin-right: 20px;">
<button class="btn dropdown-toggle" data-toggle="dropdown">branch: <strong>@branch</strong> <span class="caret"></span></button> <button class="btn dropdown-toggle" data-toggle="dropdown">branch: <strong>@branch</strong> <span class="caret"></span></button>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
@repository.branchList.map { branch => @repository.branchList.map { branch =>
<li><a href="/@repository.owner/@repository.name/@if(active=="commits"){commits} else {tree}/@branch">@branch</a></li> <li><a href="@path/@repository.owner/@repository.name/@if(active=="commits"){commits} else {tree}/@branch">@branch</a></li>
} }
</ul> </ul>
</div> </div>
</li> </li>
<li@if(active=="files"){ class="active"}><a href="/@repository.owner/@repository.name/tree/@branch">Files</a></li> <li@if(active=="files"){ class="active"}><a href="@path/@repository.owner/@repository.name/tree/@branch">Files</a></li>
<li@if(active=="commits"){ class="active"}><a href="/@repository.owner/@repository.name/commits/@branch">Commits</a></li> <li@if(active=="commits"){ class="active"}><a href="@path/@repository.owner/@repository.name/commits/@branch">Commits</a></li>
<li@if(active=="tags"){ class="active"}><a href="#">Tags</a></li> <li@if(active=="tags"){ class="active"}><a href="#">Tags</a></li>
<li class="pull-right"> <li class="pull-right">
<div class="input-prepend"> <div class="input-prepend">

View File

@@ -1,6 +1,7 @@
@() @()(implicit context: app.Context)
@import context._
@main("Create a New Repository"){ @main("Create a New Repository"){
<form id="form" method="post" action="/new" validate="true"> <form id="form" method="post" action="@path/new" validate="true">
<fieldset> <fieldset>
<label for="name"><strong>Repository name</strong></label> <label for="name"><strong>Repository name</strong></label>
<input type="text" name="name" id="name" /> <input type="text" name="name" id="name" />

View File

@@ -1,4 +1,5 @@
@(user: String, repositories: List[app.RepositoryInfo]) @(user: String, repositories: List[app.RepositoryInfo])(implicit context: app.Context)
@import context._
@main(user){ @main(user){
<div class="container-fluid"> <div class="container-fluid">
<div class="row-fluid"> <div class="row-fluid">
@@ -24,7 +25,7 @@
</ul> </ul>
@repositories.map { repository => @repositories.map { repository =>
<div class="block"> <div class="block">
<div class="block-header-2"><a href="/@user/@repository.name">@repository.name</a></div> <div class="block-header-2"><a href="@path/@user/@repository.name">@repository.name</a></div>
<div>xxxxxxxxxxxxxxxxxxxx</div> <div>xxxxxxxxxxxxxxxxxxxx</div>
<div><span class="description small">Last updated: yyyy/mm/dd</span></div> <div><span class="description small">Last updated: yyyy/mm/dd</span></div>
</div> </div>