@@ -24,6 +24,7 @@ import org.apache.commons.io.FileUtils
2424import org .eclipse .jgit .api .Git
2525import org .eclipse .jgit .lib ._
2626import org .scalatra .Ok
27+ import play .twirl .api .Html
2728
2829class GistController extends GistControllerBase with GistService with GistCommentService with AccountService
2930 with GistEditorAuthenticator with UsersAuthenticator
@@ -47,25 +48,7 @@ trait GistControllerBase extends ControllerBase {
4748 if (context.loginAccount.isDefined){
4849 val gists = getRecentGists(context.loginAccount.get.userName, 0 , 4 )
4950 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()
6952 }
7053
7154 get(" /gist/:userName/:repoName" ){
@@ -292,23 +275,8 @@ trait GistControllerBase extends ControllerBase {
292275 html.editor(count, " " , JGitUtil .ContentInfo (" text" , None , Some (" UTF-8" )))
293276 }
294277
295- get(" /gist/_public" ){
296- val page = request.getParameter(" page" ) match {
297- case " " | null => 1
298- case s => s.toInt
299- }
300- val result = getPublicGists((page - 1 ) * Limit , Limit )
301- val count = countPublicGists()
302-
303- val gists : Seq [(Gist , GistInfo )] = result.map { gist =>
304- val userName = gist.userName
305- val repoName = gist.repositoryName
306- val files = getGistFiles(userName, repoName)
307- val (fileName, source) = files.head
308-
309- (gist, GistInfo (fileName, source, files.length, getForkedCount(userName, repoName), getCommentCount(userName, repoName)))
310- }
311- html.list(None , gists, page, page * Limit < count)
278+ get(" /gist/discover" ){
279+ _discoverGists()
312280 }
313281
314282 // //////////////////////////////////////////////////////////////////////////////
@@ -422,9 +390,8 @@ trait GistControllerBase extends ControllerBase {
422390 } getOrElse {
423391 contentType = formats(" json" )
424392 org.json4s.jackson.Serialization .write(
425- Map (" content" -> gitbucket.core.view.Markdown .toHtml(comment.content,
426- gist.toRepositoryInfo, false , true , true , true ) // TODO isEditableこれでいいのか?
427- ))
393+ Map (" content" -> gitbucket.core.view.Markdown .toHtml(comment.content, gist.toRepositoryInfo, false , true , true , true ))
394+ )
428395 }
429396 }
430397 } getOrElse NotFound
@@ -446,8 +413,27 @@ trait GistControllerBase extends ControllerBase {
446413 // Private Methods
447414 //
448415 // //////////////////////////////////////////////////////////////////////////////
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+ }
449435
450- 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 = {
451437 repoName match {
452438 case None => {
453439 val page = params.get(" page" ) match {
0 commit comments