diff --git a/src/Gist/Controller/Controller.php b/src/Gist/Controller/Controller.php index 6babb1c..c13fd38 100644 --- a/src/Gist/Controller/Controller.php +++ b/src/Gist/Controller/Controller.php @@ -20,6 +20,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. * @@ -88,6 +109,7 @@ abstract class Controller return array( 'gist' => $gist, 'type' => $gist->getType(), + 'types' => $this->types, 'history' => $history, 'commit' => $commit, 'raw_content' => $content, diff --git a/src/Gist/Controller/ViewController.php b/src/Gist/Controller/ViewController.php index efbce98..8ea5002 100644 --- a/src/Gist/Controller/ViewController.php +++ b/src/Gist/Controller/ViewController.php @@ -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'); diff --git a/src/Gist/Resources/views/View/embed.html.twig b/src/Gist/Resources/views/View/embed.html.twig index 6f15c78..d1ee417 100644 --- a/src/Gist/Resources/views/View/embed.html.twig +++ b/src/Gist/Resources/views/View/embed.html.twig @@ -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 %} +
- {{ commit|slice(0, 10) }} + {{ commit|slice(0, 10) }} {% if not gist.cipher %} - + {{ 'gist.action.raw'|trans }} - + {{ 'gist.action.download'|trans }} {% endif %} - + {{ 'gist.action.clone'|trans }} diff --git a/src/Gist/Resources/views/View/embedJs.html.twig b/src/Gist/Resources/views/View/embedJs.html.twig index af08fd9..8e55f0b 100644 --- a/src/Gist/Resources/views/View/embedJs.html.twig +++ b/src/Gist/Resources/views/View/embedJs.html.twig @@ -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(''); } diff --git a/src/Gist/Resources/views/View/view.html.twig b/src/Gist/Resources/views/View/view.html.twig index 29ffc5d..0aed8e4 100644 --- a/src/Gist/Resources/views/View/view.html.twig +++ b/src/Gist/Resources/views/View/view.html.twig @@ -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 %} + +
+
+
+
+ + +
+
+
+
@@ -115,7 +148,7 @@
{{ '
-' }} +' }}