@@ -24,6 +24,7 @@ import org.apache.commons.io.FileUtils
24
24
import org .eclipse .jgit .api .Git
25
25
import org .eclipse .jgit .lib ._
26
26
import org .scalatra .Ok
27
+ import play .twirl .api .Html
27
28
28
29
class GistController extends GistControllerBase with GistService with GistCommentService with AccountService
29
30
with GistEditorAuthenticator with UsersAuthenticator
@@ -47,25 +48,7 @@ trait GistControllerBase extends ControllerBase {
47
48
if (context.loginAccount.isDefined){
48
49
val gists = getRecentGists(context.loginAccount.get.userName, 0 , 4 )
49
50
html.edit(gists, None , Seq ((" " , JGitUtil .ContentInfo (" text" , None , Some (" UTF-8" )))))
50
- } else {
51
- val page = request.getParameter(" page" ) match {
52
- case " " | null => 1
53
- case s => s.toInt
54
- }
55
- val result = getPublicGists((page - 1 ) * Limit , Limit )
56
- val count = countPublicGists()
57
-
58
- val gists : Seq [(Gist , GistInfo )] = result.map { gist =>
59
- val userName = gist.userName
60
- val repoName = gist.repositoryName
61
- val files = getGistFiles(userName, repoName)
62
- val (fileName, source) = files.head
63
-
64
- (gist, GistInfo (fileName, getLines(source), files.length, getForkedCount(userName, repoName), getCommentCount(userName, repoName)))
65
- }
66
-
67
- html.list(None , gists, page, page * Limit < count)
68
- }
51
+ } else _discoverGists()
69
52
}
70
53
71
54
get(" /gist/:userName/:repoName" ){
@@ -292,6 +275,10 @@ trait GistControllerBase extends ControllerBase {
292
275
html.editor(count, " " , JGitUtil .ContentInfo (" text" , None , Some (" UTF-8" )))
293
276
}
294
277
278
+ get(" /gist/discover" ){
279
+ _discoverGists()
280
+ }
281
+
295
282
// //////////////////////////////////////////////////////////////////////////////
296
283
//
297
284
// Fork Actions
@@ -403,9 +390,8 @@ trait GistControllerBase extends ControllerBase {
403
390
} getOrElse {
404
391
contentType = formats(" json" )
405
392
org.json4s.jackson.Serialization .write(
406
- Map (" content" -> gitbucket.core.view.Markdown .toHtml(comment.content,
407
- gist.toRepositoryInfo, false , true , true , true ) // TODO isEditableこれでいいのか?
408
- ))
393
+ Map (" content" -> gitbucket.core.view.Markdown .toHtml(comment.content, gist.toRepositoryInfo, false , true , true , true ))
394
+ )
409
395
}
410
396
}
411
397
} getOrElse NotFound
@@ -427,8 +413,27 @@ trait GistControllerBase extends ControllerBase {
427
413
// Private Methods
428
414
//
429
415
// //////////////////////////////////////////////////////////////////////////////
416
+ private def _discoverGists (): Html = {
417
+ val page = request.getParameter(" page" ) match {
418
+ case " " | null => 1
419
+ case s => s.toInt
420
+ }
421
+ val result = getVisibleGists((page - 1 ) * Limit , Limit , None )
422
+ val count = countPublicGists()
423
+
424
+ val gists : Seq [(Gist , GistInfo )] = result.map { gist =>
425
+ val userName = gist.userName
426
+ val repoName = gist.repositoryName
427
+ val files = getGistFiles(userName, repoName)
428
+ val (fileName, source) = files.head
429
+
430
+ (gist, GistInfo (fileName, getLines(source), files.length, getForkedCount(userName, repoName), getCommentCount(userName, repoName)))
431
+ }
432
+
433
+ html.list(None , gists, page, page * Limit < count)
434
+ }
430
435
431
- private def _gist (userName : String , repoName : Option [String ] = None , revision : String = " master" ) = {
436
+ private def _gist (userName : String , repoName : Option [String ] = None , revision : String = " master" ): Html = {
432
437
repoName match {
433
438
case None => {
434
439
val page = params.get(" page" ) match {
0 commit comments