Browse Source

fix issue #4

tags/v1.12.0
Simon Vieille 6 months ago
parent
commit
cb286ce704
Signed by: Simon Vieille <simon@deblan.fr> GPG Key ID: 03383D15A1D31745

+ 22
- 0
src/Gist/Controller/Controller.php View File

@@ -21,6 +21,27 @@ abstract class Controller
protected $app;

/**
* @var array
*/
protected $types = [
'html',
'css',
'javascript',
'php',
'sql',
'xml',
'yaml',
'markdown',
'perl',
'c',
'asp',
'python',
'bash',
'actionscript3',
'text',
];

/**
* __construct.
*
* @param Application $app
@@ -88,6 +109,7 @@ abstract class Controller
return array(
'gist' => $gist,
'type' => $gist->getType(),
'types' => $this->types,
'history' => $history,
'commit' => $commit,
'raw_content' => $content,

+ 27
- 0
src/Gist/Controller/ViewController.php View File

@@ -31,6 +31,15 @@ class ViewController extends Controller
$viewOptions = $this->getViewOptions($request, $gist, $commit);

if (is_array($viewOptions)) {
if ($request->query->has('type')) {
$type = $request->query->get('type');

if (in_array($type, $this->types)) {
$viewOptions['gist']->setType($type);
$viewOptions['type_overrided'] = true;
}
}

$viewOptions['no_cache'] = true;

return $this->createResponse('View/view.html.twig', $viewOptions);
@@ -55,6 +64,15 @@ class ViewController extends Controller
$viewOptions = $this->getViewOptions($request, $gist, $commit);

if (is_array($viewOptions)) {
if ($request->query->has('type')) {
$type = $request->query->get('type');

if (in_array($type, $this->types)) {
$viewOptions['gist']->setType($type);
$viewOptions['type_overrided'] = true;
}
}

return $this->createResponse('View/embed.html.twig', $viewOptions);
} else {
return $this->notFoundResponse();
@@ -74,6 +92,15 @@ class ViewController extends Controller
{
$viewOptions = $this->getViewOptions($request, $gist, $commit);

if ($request->query->has('type')) {
$type = $request->query->get('type');

if (in_array($type, $this->types)) {
$viewOptions['gist']->setType($type);
$viewOptions['type_overrided'] = true;
}
}

$response = $this->createResponse('View/embedJs.html.twig', $viewOptions);
$response->headers->set('Content-Type', 'text/javascript');


+ 14
- 8
src/Gist/Resources/views/View/embed.html.twig View File

@@ -31,6 +31,12 @@
{% block nav %}{% endblock %}

{% block body %}
{% set routeParams = app.request.attributes.get('_route_params') %}

{% if type_overrided is defined %}
{% set routeParams = routeParams|merge({type: gist.type}) %}
{% endif %}

<div class="row">
<div class="col-md-12" id="embed">
<div class="panel panel-default">
@@ -47,7 +53,7 @@
</button>
<ul class="dropdown-menu dropdown-menu-right">
<li>
<a target="_blank" href="{{ path('view', app.request.attributes.get('_route_params')) }}" class="cipher-link">
<a target="_blank" href="{{ path('view', routeParams) }}" class="cipher-link">
<span class="btn btn-warning btn-xs">
{{ commit|slice(0, 10) }}
</span>
@@ -55,18 +61,18 @@
</li>
{% if not gist.cipher %}
<li>
<a target="_blank" href="{{ path('raw', app.request.attributes.get('_route_params')) }}">
<a target="_blank" href="{{ path('raw', routeParams) }}">
{{ 'gist.action.raw'|trans }}
</a>
</li>
<li>
<a target="_blank" href="{{ path('download', app.request.attributes.get('_route_params')) }}">
<a target="_blank" href="{{ path('download', routeParams) }}">
{{ 'gist.action.download'|trans }}
</a>
</li>
{% endif %}
<li>
<a target="_blank" href="{{ path('clone', app.request.attributes.get('_route_params')) }}" class="cipher-link">
<a target="_blank" href="{{ path('clone', routeParams) }}" class="cipher-link">
{{ 'gist.action.clone'|trans }}
</a>
</li>
@@ -75,20 +81,20 @@
</div>
<div class="visible-md visible-lg">
<div class="text-right actions">
<a target="_blank" href="{{ path('view', app.request.attributes.get('_route_params')) }}" class="cipher-link"><span class="btn btn-warning btn-xs">{{ commit|slice(0, 10) }}</span></a>
<a target="_blank" href="{{ path('view', routeParams) }}" class="cipher-link"><span class="btn btn-warning btn-xs">{{ commit|slice(0, 10) }}</span></a>

{% if not gist.cipher %}
<a target="_blank" href="{{ path('raw', app.request.attributes.get('_route_params')) }}" class="btn btn-default btn-sm">
<a target="_blank" href="{{ path('raw', routeParams) }}" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-eye-open"></span>
{{ 'gist.action.raw'|trans }}
</a>
<a target="_blank" href="{{ path('download', app.request.attributes.get('_route_params')) }}" class="btn btn-default btn-sm">
<a target="_blank" href="{{ path('download', routeParams) }}" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-save-file"></span>
{{ 'gist.action.download'|trans }}
</a>
{% endif %}

<a target="_blank" href="{{ path('clone', app.request.attributes.get('_route_params')) }}" class="btn btn-success btn-sm cipher-link">
<a target="_blank" href="{{ path('clone', routeParams) }}" class="btn btn-success btn-sm cipher-link">
<span class="glyphicon glyphicon-copy"></span>
{{ 'gist.action.clone'|trans }}
</a>

+ 8
- 2
src/Gist/Resources/views/View/embedJs.html.twig View File

@@ -1,10 +1,16 @@
{% set routeParams = app.request.attributes.get('_route_params') %}

{% if type_overrided is defined %}
{% set routeParams = routeParams|merge({type: gist.type}) %}
{% endif %}

(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')) }}';
var url = '{{ app.request.getSchemeAndHttpHost() ~ path('embed', routeParams) }}';
if (div.getAttribute('data-key')) {
url = [url, div.getAttribute('data-key')].join('');
}

+ 41
- 8
src/Gist/Resources/views/View/view.html.twig View File

@@ -15,6 +15,12 @@
{% block title %}{{ gist.title ? gist.title : 'gist.untitled'|trans }} - {{ commit|slice(0, 10) }}{% endblock %}

{% block body %}
{% set routeParams = app.request.attributes.get('_route_params') %}

{% if type_overrided is defined %}
{% set routeParams = routeParams|merge({type: gist.type}) %}
{% endif %}

<div class="row">
<div class="col-md-12">
<ul class="nav nav-tabs">
@@ -45,7 +51,7 @@
</button>
<ul class="dropdown-menu dropdown-menu-right">
<li>
<a target="_blank" href="{{ path('view', app.request.attributes.get('_route_params')) }}" class="cipher-link">
<a target="_blank" href="{{ path('view', routeParams) }}" class="cipher-link">
<span class="btn btn-warning btn-xs">
{{ commit|slice(0, 10) }}
</span>
@@ -53,18 +59,18 @@
</li>
{% if not gist.cipher %}
<li>
<a href="{{ path('raw', app.request.attributes.get('_route_params')) }}">
<a href="{{ path('raw', routeParams) }}">
{{ 'gist.action.raw'|trans }}
</a>
</li>
<li>
<a href="{{ path('download', app.request.attributes.get('_route_params')) }}">
<a href="{{ path('download', routeParams) }}">
{{ 'gist.action.download'|trans }}
</a>
</li>
{% endif %}
<li>
<a href="{{ path('clone', app.request.attributes.get('_route_params')) }}" class="cipher-link">
<a href="{{ path('clone', routeParams) }}" class="cipher-link">
{{ 'gist.action.clone'|trans }}
</a>
</li>
@@ -78,17 +84,17 @@
</span>

{% if not gist.cipher %}
<a href="{{ path('raw', app.request.attributes.get('_route_params')) }}" class="btn btn-default btn-sm">
<a href="{{ path('raw', routeParams) }}" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-eye-open"></span>
{{ 'gist.action.raw'|trans }}
</a>
<a href="{{ path('download', app.request.attributes.get('_route_params')) }}" class="btn btn-default btn-sm">
<a href="{{ path('download', routeParams) }}" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-save-file"></span>
{{ 'gist.action.download'|trans }}
</a>
{% endif %}

<a href="{{ path('clone', app.request.attributes.get('_route_params')) }}" class="btn btn-success btn-sm cipher-link">
<a href="{{ path('clone', routeParams) }}" class="btn btn-success btn-sm cipher-link">
<span class="glyphicon glyphicon-copy"></span>
{{ 'gist.action.clone'|trans }}
</a>
@@ -104,6 +110,33 @@
<pre><code {% if gist.cipher %}data-cipher{% endif %} class="line-numbers language-{{ gist.highlightType }}">{{ raw_content }}</code></pre>
</div>
</div>
<div class="btn-toolbar">
<div class="pull-right">
<div class="btn-group">
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
{{ ('form.type.choice.' ~ gist.type)|trans }}
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right">
{% for item in types %}
{% if gist.type != item %}
<li>
{% set params = app.request.attributes.get('_route_params')|merge({type: item}) %}

<a href="{{ path('view', params) }}">
<label for="type-{{ loop.index }}">
{{ ('form.type.choice.' ~ item)|trans }}
</label>
</a>
</li>
{% endif %}
{% endfor %}
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@@ -115,7 +148,7 @@
<div class="tab-content">
<div class="tab-pane active in">
<pre><code class="language-html">{{ '<div%key%id="gist-' ~ gist.file ~ '-' ~ commit ~ '" class="gist-container"></div>
<script src="' ~ app.request.getSchemeAndHttpHost() ~ path('embedjs', app.request.attributes.get('_route_params')) ~ '" async></script>' }}</code></pre>
<script src="' ~ app.request.getSchemeAndHttpHost() ~ path('embedjs', routeParams) ~ '" async></script>' }}</code></pre>
</div>
</div>
</div>

Loading…
Cancel
Save