Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/main/scala/gitbucket/gist/controller/GistController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"))
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/gitbucket/gist/util/GistUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
54 changes: 54 additions & 0 deletions src/main/twirl/gitbucket/gist/detail.scala.js
Original file line number Diff line number Diff line change
@@ -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
<div class="content-wrapper main-center">
<div class="content body">
<div style="overflow: hidden;">
<div style="margin-bottom: 10px;">
@gist.description
</div>
@files.map { case (fileName, content) =>
<div class="panel panel-default">
<div class="panel-heading strong" style="padding: 6px; line-height: 30px;">
@fileName
<div class="pull-right">
<a href="@context.path/gist/@gist.userName/@gist.repositoryName/raw/@revision/@fileName" class="btn btn-sm btn-default">Raw</a>
</div>
</div>
@if(helpers.isRenderable(fileName)){
<div class="panel-body markdown-body" style="padding-left: 16px; padding-right: 16px;">
@helpers.renderMarkup(List(fileName), content, "master", gist.toRepositoryInfo, false, false, true)
</div>
} else {
<div class="panel-body">
<pre class="prettyprint linenums blob">@content.toString.replaceAll("<","&lt;").replaceAll(">","&gt;")<pre>
</div>
}
</div>
}
</div>
</div>
</div>
4f85e035-2513-453b-b435-33f0a12b2339*/}).toString().replace(/(\n)/g, '').split('4f85e035-2513-453b-b435-33f0a12b2339')[1];

document.write('<link href="@helpers.assets("/vendors/bootstrap-3.3.6/css/bootstrap.css")" rel="stylesheet">');
document.write('<link href="@helpers.assets("/vendors/google-code-prettify/prettify.css")" rel="stylesheet">');
document.write('<link href="@context.path/plugin-assets/gist/style.css" rel="stylesheet">');
document.write('<link href="@helpers.assets("/common/css/gitbucket.css")" rel="stylesheet">');
document.write('<link href="@helpers.assets("/vendors/AdminLTE-2.3.8/css/AdminLTE.min.css")" rel="stylesheet">');
document.write(_html.replace(/\\r\\n/g,"\n").replace(/\\/g,""));
51 changes: 39 additions & 12 deletions src/main/twirl/gitbucket/gist/menu.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
gist: gitbucket.gist.model.Gist,
repositoryUrl: gitbucket.gist.util.GistUtils.GistRepositoryURL)(implicit context: gitbucket.core.controller.Context)
@import gitbucket.core.view.helpers

@embedScript=@{"<script>"+repositoryUrl.embedUrl+"</script>"}
@menuitem(name: String, path: String, label: String, count: Int = 0) = {
<li @if(active == name){class="active"}>
<a href="@context.path/gist/@path">
Expand Down Expand Up @@ -32,33 +32,60 @@
"Forks")
}
</ul>
<div class="small">
<strong id="repository-url-proto">HTTP</strong> <span class="mute">clone URL</span>
</div>
<div class="pull-right pc">
<div class="input-group" style="margin-bottom: 0px;">
<div class="btn-group input-group-btn">
<button type="button" class="btn btn-sm btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span id="repository-url-proto">HTTP</span> <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>
<a href="javascript:void(0);" id="repository-url-embed">
<strong>Embed</strong><br>
Embed this snippet in your website.
</a>
</li>
<li>
<a href="javascript:void(0);" id="repository-url-http">
<strong>HTTP</strong><br>
Clone with Git using the repository's web address.
</a>
</li>
@if(context.settings.ssh && context.loginAccount.isDefined){
<li>
<a href="javascript:void(0);" id="repository-url-ssh">
<strong>SSH</strong><br>
Clone with an SSH key and passphrase from your GitBucket Settings.
</a>
</li>
}
</ul>
</div>
@gitbucket.core.helper.html.copy("repository-url", "repository-url-copy", repositoryUrl.httpUrl){
<input type="text" value="@repositoryUrl.httpUrl" id="repository-url" class="form-control input-sm" readonly>
}
@if(context.settings.ssh && context.loginAccount.isDefined){
<div class="small">
<span class="mute">You can clone <a href="javascript:void(0);" id="repository-url-http">HTTP</a> or <a href="javascript:void(0);" id="repository-url-ssh">SSH</a>.</span>
</div>
}
</div>
<div style="margin-top: 10px;">
<a href="@context.path/gist/@{gist.userName}/@{gist.repositoryName}/download/@{gist.repositoryName}.zip"
class="btn btn-default btn-block"><i class="icon-download-alt"></i>Download ZIP</a>
class="btn btn-default btn-block"><i class="octicon octicon-cloud-download"></i>Download ZIP</a>
</div>
</div>
@if(context.settings.ssh && context.loginAccount.isDefined){
</div>
<script>
$(function(){
$('#repository-url-embed').click(function(){
$('#repository-url').val('@embedScript'.replace(/&lt;/g,"<").replace(/&gt;/g,">"));
$('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val());
});
$('#repository-url-http').click(function(){
$('#repository-url').val('@repositoryUrl.httpUrl');
$('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val());
});
@if(context.settings.ssh && context.loginAccount.isDefined){
$('#repository-url-ssh').click(function(){
$('#repository-url').val('@repositoryUrl.sshUrl(context.loginAccount.get.userName)');
$('#repository-url-copy').attr('data-clipboard-text', $('#repository-url').val());
});
}
});
</script>
}