diff --git a/src/main/scala/gitbucket/gist/controller/GistController.scala b/src/main/scala/gitbucket/gist/controller/GistController.scala index c8be216..55ade11 100644 --- a/src/main/scala/gitbucket/gist/controller/GistController.scala +++ b/src/main/scala/gitbucket/gist/controller/GistController.scala @@ -19,12 +19,14 @@ import gitbucket.gist.util._ import gitbucket.gist.util.GistUtils._ import gitbucket.gist.util.Configurations._ import gitbucket.gist.html +import gitbucket.gist.js import org.apache.commons.io.FileUtils import org.eclipse.jgit.api.Git import org.eclipse.jgit.lib._ import org.scalatra.Ok import play.twirl.api.Html +import play.twirl.api.JavaScript class GistController extends GistControllerBase with GistService with GistCommentService with AccountService with GistEditorAuthenticator with UsersAuthenticator @@ -68,6 +70,17 @@ trait GistControllerBase extends ControllerBase { _gist(params("userName"), Some(params("repoName"))) } + get("/gist/:userName/:repoName.js"){ + val userName = params("userName") + val repoName = params("repoName") + getGist(userName, repoName) match { + case Some(gist) => + _embedJs(gist, userName, repoName, "master") + case None => + NotFound() + } + } + get("/gist/:userName/:repoName/:revision"){ _gist(params("userName"), Some(params("repoName")), params("revision")) } @@ -456,6 +469,18 @@ trait GistControllerBase extends ControllerBase { } } + private def _embedJs(gist: Gist, userName: String, repoName: String, revision: String): JavaScript = { + val originUserName = gist.originUserName.getOrElse(userName) + val originRepoName = gist.originRepositoryName.getOrElse(repoName) + + js.detail( + gist, + GistRepositoryURL(gist, baseUrl, context.settings), + revision, + getGistFiles(userName, repoName, revision) + ) + } + private def _gistDetail(gist: Gist, userName: String, repoName: String, revision: String): Html = { val originUserName = gist.originUserName.getOrElse(userName) val originRepoName = gist.originRepositoryName.getOrElse(repoName) diff --git a/src/main/scala/gitbucket/gist/util/GistUtils.scala b/src/main/scala/gitbucket/gist/util/GistUtils.scala index 35f8c65..4739d02 100644 --- a/src/main/scala/gitbucket/gist/util/GistUtils.scala +++ b/src/main/scala/gitbucket/gist/util/GistUtils.scala @@ -47,6 +47,8 @@ object GistUtils { case class GistRepositoryURL(gist: Gist, baseUrl: String, settings: SystemSettings){ def httpUrl: String = s"${baseUrl}/git/gist/${gist.userName}/${gist.repositoryName}.git" + + def embedUrl: String = s"${baseUrl}/gist/${gist.userName}/${gist.repositoryName}.js" def sshUrl(loginUser: String): String = { val host = """^https?://(.+?)(:\d+)?/""".r.findFirstMatchIn(httpUrl).get.group(1) diff --git a/src/main/twirl/gitbucket/gist/detail.scala.js b/src/main/twirl/gitbucket/gist/detail.scala.js new file mode 100644 index 0000000..39773d9 --- /dev/null +++ b/src/main/twirl/gitbucket/gist/detail.scala.js @@ -0,0 +1,54 @@ +@(gist: gitbucket.gist.model.Gist, + repositoryUrl: gitbucket.gist.util.GistUtils.GistRepositoryURL, + revision: String, + files: Seq[(String, String)] + )(implicit context: gitbucket.core.controller.Context) +@import gitbucket.core.view.helpers +jqueryScript = document.createElement('script'); +jqueryScript.src = '@helpers.assets("/vendors/jquery/jquery-1.12.2.min.js")'; +document.head.appendChild(jqueryScript); +prettifyScript = document.createElement('script'); +prettifyScript.src = '@helpers.assets("/vendors/google-code-prettify/prettify.js")'; +prettifyScript.onload = function() { prettyPrint(); $('pre:has(> span.pln)').hide(); }; +document.head.appendChild(prettifyScript); +fireScript = document.createElement('script'); +fireScript.setAttribute('type','text/javascript'); +fireScript.text = '$(document).load(function() { prettyPrint(); });' + +var _html = (function () {/*4f85e035-2513-453b-b435-33f0a12b2339 +