1
0
mirror of https://gitnet.fr/deblan/gist.git synced 2021-08-14 08:30:49 +02:00

Encrypted code embeding, pages titles

This commit is contained in:
Simon Vieille 2015-05-11 21:06:41 +02:00
parent b06b03f573
commit 5771fdb568
8 changed files with 87 additions and 58 deletions

View File

@ -1,6 +1,6 @@
{
"name": "gist",
"version": "0.0.2",
"version": "0.0.3",
"authors": [
"Simon Vieille <simon@deblan.fr>"
],

View File

@ -1,5 +1,7 @@
{% extends 'base.html.twig' %}
{% block title %}{{ gist.title ? gist.title : 'gist.untitled'|trans }} - {{ 'gist.action.clone'|trans }}{% endblock %}
{% block body %}
<div class="row">
<form action="" method="post" id="main-form">

View File

@ -1,5 +1,7 @@
{% extends 'base.html.twig' %}
{% block title %}{{ 'app.menu.home.title'|trans }}{% endblock %}
{% block body %}
<div class="row">
<form action="{{ path('home') }}" method="post" id="main-form">

View File

@ -1,7 +1,12 @@
{% extends 'base.html.twig' %}
{% block css %}
{% if gist.cipher %}
<link type="text/css" rel="Stylesheet" href="{{ web_path }}components/SyntaxHighlighter/styles/shCoreRDark.css" />
<link type="text/css" rel="Stylesheet" href="{{ web_path }}components/SyntaxHighlighter/styles/shThemeRDark.css" />
{% else %}
<link rel="stylesheet" href="{{ web_path }}app/css/geshi/vibrant-ink.css" />
{% endif %}
{{ parent() }}
@ -90,4 +95,37 @@
{{ parent() }}
<script type="text/javascript" src="{{ web_path }}components/iframe-resizer/js/iframeResizer.contentWindow.min.js"></script>
{% 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>
{% endif %}
{% endblock %}

View File

@ -1,10 +1,17 @@
(function() {
var iFrameResizeLoaded = function() {
var div = document.getElementById('gist-{{ gist.file }}-{{ commit }}');
var iframeId = 'gist-' + (Math.floor(Math.random() * (10000 - 1)) + 1).toString();
var iframe = document.createElement('iframe');
var url = '{{ app.request.getSchemeAndHttpHost() ~ path('embed', app.request.attributes.get('_route_params')|merge({_locale: 'en'})) }}';
if (div.getAttribute('data-key')) {
url = [url, div.getAttribute('data-key')].join('');
}
iframe.setAttribute('id', iframeId);
iframe.setAttribute('frameborder', 0);
iframe.setAttribute('src', '{{ app.request.getSchemeAndHttpHost() ~ path('embed', app.request.attributes.get('_route_params')|merge({_locale: 'en'})) }}');
iframe.setAttribute('src', url);
iframe.setAttribute('style', 'width: 100%');
document.getElementById('gist-{{ gist.file }}-{{ commit }}').appendChild(iframe);

View File

@ -6,6 +6,8 @@
{{ parent() }}
{% endblock %}
{% block title %}{{ gist.title ? gist.title : 'gist.untitled'|trans }} - {{ 'gist.action.history'|trans }}{% endblock %}
{% block body %}
<div class="row">
<div class="col-md-12">

View File

@ -1,11 +1,11 @@
{% extends 'base.html.twig' %}
{% block css %}
<link rel="stylesheet" href="{{ web_path }}app/css/geshi/vibrant-ink.css" />
{% if gist.cipher %}
<link type="text/css" rel="Stylesheet" href="{{ web_path }}components/SyntaxHighlighter/styles/shCoreRDark.css" />
<link type="text/css" rel="Stylesheet" href="{{ web_path }}components/SyntaxHighlighter/styles/shThemeRDark.css" />
{% else %}
<link rel="stylesheet" href="{{ web_path }}app/css/geshi/vibrant-ink.css" />
{% endif %}
{{ parent() }}
@ -70,45 +70,9 @@
<p id="embed" class="pull-right">
{{ 'gist.action.embed'|trans }}
<input type="text" class="form-control" value="{{ '<div id="gist-' ~ gist.file ~ '-' ~ commit ~ '" class="gist-container"></div><script src="' ~ app.request.getSchemeAndHttpHost() ~ path('embedjs', app.request.attributes.get('_route_params')) ~ '"></script>' }}" />
<input type="text" class="form-control" id="embed-input" value="{{ '<div%key%id="gist-' ~ gist.file ~ '-' ~ commit ~ '" class="gist-container"></div><script src="' ~ app.request.getSchemeAndHttpHost() ~ path('embedjs', app.request.attributes.get('_route_params')) ~ '"></script>' }}" />
</p>
</div>
{% if not gist.cipher %}
<div id="revisions" class="tab-pane out">
{% for commit in history %}
<div class="commit">
<p>
<a href="{{ path('view', {gist: gist.file, commit: commit.commit}) }}" class="btn btn-warning btn-sm">
{{ commit.commit|slice(0, 10) }}
</a>
{% if loop.first %}<span class="btn btn-info btn-sm">init</span>{% endif %}
{% if not loop.first %}
<a href="#diff-{{ loop.index }}" data-target="#diff-{{ loop.index }}" class="btn btn-default btn-sm show-diff">
diff
</a>
{% endif %}
</p>
<p>
{{ commit.date|date('date.format'|trans) }}
</p>
<div>
{% if not loop.first %}
<div class="diff" id="diff-{{ loop.index }}">
{{ commit.diff|raw }}
</div>
{% endif %}
</div>
</div>
{% if not loop.last %}
<hr />
{% endif %}
{% endfor %}
</div>
{% endif %}
</div>
</div>
</div>

View File

@ -100,23 +100,37 @@ var mainEditorEvents = function() {
});
}
var viewerEvents = function() {
var $render = $('.syntaxhighlighter');
if (0 === $render.length) {
return;
}
$(document).ready(function() {
var getKey = function() {
var url = document.location.href;
var parts = url.split('#key=');
if (parts.length === 2) {
var decrypted = CryptoJS.AES.decrypt($render.html(), parts[1], {
return parts[1];
}
return null;
}
var viewerEvents = function() {
var $render = $('.syntaxhighlighter');
$(document).ready(function() {
var key = getKey();
var $embedInput = $('#embed-input');
var to = ' ';
if (0 !== $render.length && key) {
var decrypted = CryptoJS.AES.decrypt($render.html(), key, {
format: JsonFormatter
});
$render.text(decrypted.toString(CryptoJS.enc.Utf8));
SyntaxHighlighter.all();
to = ' data-key="#key=' + key + '" ';
}
if ($embedInput.length) {
$embedInput.val($embedInput.val().replace('%key%', to));
}
});
}