1
0
mirror of https://gitnet.fr/deblan/gist.git synced 2021-08-14 08:30:49 +02:00
This commit is contained in:
Simon Vieille 2016-09-24 16:07:35 +02:00
parent 6ab827bf94
commit 96f199adaa
7 changed files with 116 additions and 38 deletions

View File

@ -11,11 +11,12 @@
"GIT"
],
"license": "LGPL",
"homepage": "https://gitlab.deblan.org/deblan/gist.deblan.org",
"homepage": "https://gitnet.fr/deblan/gist",
"dependencies": {
"bootstrap": "3.3.4",
"flag-icon-css": "0.7.1",
"SyntaxHighlighter": "3.0.83",
"iframe-resizer": "2.8.6"
"iframe-resizer": "2.8.6",
"jsdiff": "~2.2.2"
}
}

View File

@ -39,7 +39,7 @@ class Gist extends BaseGist
{
$data = array(
'javascript' => 'js',
'yaml'=> 'yml',
'yaml' => 'yml',
'perl' => 'pl',
'python' => 'py',
'bash' => 'sh',

View File

@ -0,0 +1,30 @@
<script type="text/javascript" src="{{ web_path }}components/SyntaxHighlighter/scripts/XRegExp.js"></script> <!-- XRegExp is bundled with the final shCore.js during build -->
<script type="text/javascript" src="{{ web_path }}components/SyntaxHighlighter/scripts/shCore.js"></script>
<script type="text/javascript" src="{{ web_path }}components/SyntaxHighlighter/scripts/shAutoloader.js"></script>
<script type="text/javascript">
SyntaxHighlighter.autoloader(
['applescript', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushAppleScript.js' ],
['actionscript3', 'as3', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushAS3.js' ],
['bash', 'shell', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushBash.js' ],
['coldfusion', 'cf', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushColdFusion.js' ],
['cpp', 'c', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushCpp.js' ],
['c#', 'c-sharp', 'csharp', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushCSharp.js' ],
['css', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushCss.js' ],
['delphi', 'pascal', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushDelphi.js' ],
['diff', 'patch', 'pas', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushDiff.js' ],
['erl', 'erlang', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushErlang.js' ],
['groovy', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushGroovy.js' ],
['java', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushJava.js' ],
['jfx', 'javafx', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushJavaFX.js' ],
['js', 'jscript', 'javascript', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushJScript.js' ],
['perl', 'pl', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushPerl.js' ],
['php', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushPhp.js' ],
['text', 'plain', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushPlain.js' ],
['py', 'python', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushPython.js' ],
['ruby', 'rails', 'ror', 'rb', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushRuby.js' ],
['scala', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushScala.js' ],
['sql', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushSql.js' ],
['vb', 'vbnet', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushVb.js' ],
['xml', 'xhtml', 'xslt', 'html', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushXml.js' ]
);
</script>

View File

@ -52,9 +52,10 @@
</p>
<div>
{% if not loop.first %}
<div class="diff" id="diff-{{ loop.index }}">
{{ commit.diff|raw }}
{% if not gist.cipher %}
{{ commit.diff|raw }}
{% endif %}
</div>
{% endif %}
</div>
@ -74,4 +75,61 @@
{% block js %}
{{ parent() }}
{% if gist.cipher %}
{{ include('View/cipherJs.html.twig') }}
<script src="{{ web_path }}components/jsdiff/diff.min.js"></script>
<script>
var key = getKey();
var decrypt = function(content) {
var decrypted = CryptoJS.AES.decrypt(content, key, {
format: JsonFormatter
});
return decrypted.toString(CryptoJS.enc.Utf8);
}
var commits = [];
{% for commit in history %}
try {
var content = decrypt('{{ commit.content|raw }}');
commits[{{ loop.index - 1 }}] = content;
} catch(e) {
}
{% endfor %}
for (var u = commits.length - 1; u > 0; u--) {
if (commits.hasOwnProperty(u) && commits.hasOwnProperty(u - 1)) {
var previous = commits[u - 1];
var current = commits[u];
var diff = JsDiff.diffLines(previous, current);
var diffContent = [];
for (var v = 0, c = diff.length; v < c; v++) {
var value = diff[v].value;
var sign = diff[v].added ? '+' : '-';
var lines = value.split("\n");
for (var i = 0, l = lines.length; i < l; i++) {
diffContent.push(sign + lines[i]);
}
}
diffContent = diffContent.join("\n");
var $pre = $('<pre>')
.attr('class', 'brush: diff; syntaxhighlighter')
.html(diffContent);
$('#diff-' + (u + 1).toString()).append($pre);
}
}
SyntaxHighlighter.all();
</script>
{% endif %}
{% endblock %}

View File

@ -84,35 +84,6 @@
{{ parent() }}
{% if gist.cipher %}
<script type="text/javascript" src="{{ web_path }}components/SyntaxHighlighter/scripts/XRegExp.js"></script> <!-- XRegExp is bundled with the final shCore.js during build -->
<script type="text/javascript" src="{{ web_path }}components/SyntaxHighlighter/scripts/shCore.js"></script>
<script type="text/javascript" src="{{ web_path }}components/SyntaxHighlighter/scripts/shAutoloader.js"></script>
<script type="text/javascript">
SyntaxHighlighter.autoloader(
['applescript', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushAppleScript.js' ],
['actionscript3', 'as3', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushAS3.js' ],
['bash', 'shell', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushBash.js' ],
['coldfusion', 'cf', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushColdFusion.js' ],
['cpp', 'c', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushCpp.js' ],
['c#', 'c-sharp', 'csharp', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushCSharp.js' ],
['css', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushCss.js' ],
['delphi', 'pascal', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushDelphi.js' ],
['diff', 'patch', 'pas', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushDiff.js' ],
['erl', 'erlang', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushErlang.js' ],
['groovy', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushGroovy.js' ],
['java', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushJava.js' ],
['jfx', 'javafx', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushJavaFX.js' ],
['js', 'jscript', 'javascript', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushJScript.js' ],
['perl', 'pl', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushPerl.js' ],
['php', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushPhp.js' ],
['text', 'plain', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushPlain.js' ],
['py', 'python', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushPython.js' ],
['ruby', 'rails', 'ror', 'rb', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushRuby.js' ],
['scala', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushScala.js' ],
['sql', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushSql.js' ],
['vb', 'vbnet', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushVb.js' ],
['xml', 'xhtml', 'xslt', 'html', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushXml.js' ]
);
</script>
{{ include('View/cipherJs.html.twig') }}
{% endif %}
{% endblock %}

View File

@ -65,6 +65,10 @@ class Gist
'diff' => $this->highlight('diff', $diff),
);
if ($gist->isCipher()) {
$data['content'] = $this->getContent($gist, $commit);
}
$history[] = $data;
}

View File

@ -66,14 +66,28 @@ var editorEvents = function() {
$(this).trigger('change');
});
var key = getKey();
if (key) {
$('.show-diff').each(function() {
var href = $(this).attr('href');
href = href.replace('#', '#key=' + key + '&');
$(this).attr('href', href);
});
}
$('.show-diff').click(function() {
$($(this).data('target')).toggle();
});
if ((document.location.href).indexOf('#diff-') !== -1) {
var diffLinkTest1 = (document.location.href).indexOf('#diff-') !== -1;
var diffLinkTest2 = (document.location.href).indexOf('&diff-') !== -1;
if (diffLinkTest1 || diffLinkTest2) {
var anchor = '#' + (document.location.href).toString().split('#')[1];
$('.show-diff[href="' + anchor + '"]').click();
document.location.href = anchor;
}
}
@ -119,7 +133,7 @@ var getKey = function() {
var parts = url.split('#key=');
if (parts.length === 2) {
return parts[1];
return parts[1].split('&')[0];
}
return null;