From 11cee3c3997bcf5c200ea5fececb8c1734312ccd Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Sat, 9 May 2015 17:42:33 +0200 Subject: [PATCH] Embed --- app/config/routing.yml | 8 ++ app/locales/en.yml | 4 + app/locales/fr.yml | 4 + bower.json | 3 +- src/Gist/Controller/ViewController.php | 24 +++++ src/Gist/Resources/views/View/embed.html.twig | 93 +++++++++++++++++++ .../Resources/views/View/embedJs.html.twig | 24 +++++ src/Gist/Resources/views/View/view.html.twig | 5 + src/Gist/Resources/views/base.html.twig | 84 +++++++++-------- 9 files changed, 211 insertions(+), 38 deletions(-) create mode 100644 src/Gist/Resources/views/View/embed.html.twig create mode 100644 src/Gist/Resources/views/View/embedJs.html.twig diff --git a/app/config/routing.yml b/app/config/routing.yml index b5cefa4..8696989 100644 --- a/app/config/routing.yml +++ b/app/config/routing.yml @@ -10,6 +10,14 @@ view: path: /view/{gist}/{commit} defaults: {_controller: Gist\Controller\ViewController::viewAction, _locale: en, commit: 0} +embed: + path: /embed/{gist}/{commit} + defaults: {_controller: Gist\Controller\ViewController::embedAction, _locale: en, commit: 0} + +embedjs: + path: /embedjs/{gist}/{commit} + defaults: {_controller: Gist\Controller\ViewController::embedJsAction, _locale: en, commit: 0} + raw: path: /raw/{gist}/{commit} defaults: {_controller: Gist\Controller\ViewController::rawAction, _locale: en, commit: 0} diff --git a/app/locales/en.yml b/app/locales/en.yml index 870b3b8..a8fd24c 100644 --- a/app/locales/en.yml +++ b/app/locales/en.yml @@ -19,10 +19,14 @@ gist: raw: 'RAW' download: 'Download' clone: 'Clone' + embed: 'Embed:' date: format: 'Y-m-d h:i:s' +footer: + text: '

Powered by GIST

' + form: error: not_blank: 'This value should not be blank bro!' diff --git a/app/locales/fr.yml b/app/locales/fr.yml index 4d6d58c..31c5ba9 100644 --- a/app/locales/fr.yml +++ b/app/locales/fr.yml @@ -19,10 +19,14 @@ gist: raw: 'RAW' download: 'Télécharger' clone: 'Clôner' + embed: 'Insérer : ' date: format: 'd/m/Y H\hi s\s' +footer: + text: '

Propulsé avec GIST

' + form: error: not_blank: 'Vous devez saisir cette donnée.' diff --git a/bower.json b/bower.json index 9ccae1e..6f20eb6 100644 --- a/bower.json +++ b/bower.json @@ -15,6 +15,7 @@ "dependencies": { "bootstrap": "3.3.4", "flag-icon-css": "0.7.1", - "SyntaxHighlighter": "3.0.83" + "SyntaxHighlighter": "3.0.83", + "iframe-resizer": "2.8.6" } } diff --git a/src/Gist/Controller/ViewController.php b/src/Gist/Controller/ViewController.php index a772eb8..d26b88d 100644 --- a/src/Gist/Controller/ViewController.php +++ b/src/Gist/Controller/ViewController.php @@ -25,6 +25,30 @@ class ViewController extends Controller } } + public function embedAction(Request $request, Application $app, $gist, $commit) + { + $viewOptions = $this->getViewOptions($request, $app, $gist, $commit); + + if (is_array($viewOptions)) { + return $app['twig']->render('View/embed.html.twig', $viewOptions); + } else { + return $this->notFoundResponse($app); + } + } + + public function embedJsAction(Request $request, Application $app, $gist, $commit) + { + $viewOptions = $this->getViewOptions($request, $app, $gist, $commit); + + return new Response( + $app['twig']->render('View/embedJs.html.twig', $viewOptions), + 200, + array( + 'Content-Type' => 'text/javascript', + ) + ); + } + public function rawAction(Request $request, Application $app, $gist, $commit) { $viewOptions = $this->getViewOptions($request, $app, $gist, $commit); diff --git a/src/Gist/Resources/views/View/embed.html.twig b/src/Gist/Resources/views/View/embed.html.twig new file mode 100644 index 0000000..3a6b13b --- /dev/null +++ b/src/Gist/Resources/views/View/embed.html.twig @@ -0,0 +1,93 @@ +{% extends 'base.html.twig' %} + +{% block css %} + + + {{ parent() }} + + +{% endblock %} + +{% block title %}{{ gist.title ? gist.title : 'gist.untitled'|trans }} - {{ commit|slice(0, 10) }}{% endblock %} + +{% block nav %}{% endblock %} + +{% block body %} +
+
+
+
+ {% if not gist.cipher %} + + {% endif %} + + {{ gist.title ? gist.title : 'gist.untitled'|trans }} +
+
+
+
+
+ {% if gist.cipher %} +
{{ raw_content|raw }}
+ {% else %} + {{ content|raw }} + {% endif %} +
+
+
+
+
+
+
+{% endblock %} + +{% block footer %}{% endblock %} + +{% block js %} + {{ parent() }} + + +{% endblock %} diff --git a/src/Gist/Resources/views/View/embedJs.html.twig b/src/Gist/Resources/views/View/embedJs.html.twig new file mode 100644 index 0000000..190a645 --- /dev/null +++ b/src/Gist/Resources/views/View/embedJs.html.twig @@ -0,0 +1,24 @@ +(function() { + var iFrameResizeLoaded = function() { + var iframeId = 'gist-' + (Math.floor(Math.random() * (10000 - 1)) + 1).toString(); + var iframe = document.createElement('iframe'); + 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('style', 'width: 100%'); + document.getElementById('gist-{{ gist.file }}-{{ commit }}').appendChild(iframe); + + iFrameResize({}, iframe); + } + + if (typeof iFrameResize == 'undefined') { + var script = document.createElement('script'); + script.setAttribute('id', 'gist-iframe-resizer'); + script.setAttribute('class', 'gist-iframe'); + script.setAttribute('src', '{{ app.request.getSchemeAndHttpHost() ~ web_path }}components/iframe-resizer/js/iframeResizer.min.js'); + script.onload = iFrameResizeLoaded; + document.getElementsByTagName('head')[0].appendChild(script); + } else { + iFrameResizeLoaded(); + } +})(); diff --git a/src/Gist/Resources/views/View/view.html.twig b/src/Gist/Resources/views/View/view.html.twig index 9116925..bc6566b 100644 --- a/src/Gist/Resources/views/View/view.html.twig +++ b/src/Gist/Resources/views/View/view.html.twig @@ -67,6 +67,11 @@ {{ content|raw }} {% endif %} + +

+ {{ 'gist.action.embed'|trans }} + ' }}" /> +

{% if not gist.cipher %}
diff --git a/src/Gist/Resources/views/base.html.twig b/src/Gist/Resources/views/base.html.twig index 8995b7d..559264d 100644 --- a/src/Gist/Resources/views/base.html.twig +++ b/src/Gist/Resources/views/base.html.twig @@ -16,46 +16,56 @@ {{ 'app.title_prefix'|trans }}{% block title %}{% endblock %} - + + {% endblock %} +
{% block body %}{% endblock %} + + {% block footer %} +
+
+ {{ 'footer.text'|trans|raw }} +
+ {% endblock %}
{% block js %}