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 %} +
{{ raw_content }}
{{ '
-' }}
+' }}