1
0
mirror of https://gitnet.fr/deblan/gist.git synced 2021-08-14 08:30:49 +02:00
This commit is contained in:
Simon Vieille 2015-05-05 20:33:05 +02:00
parent ba37e2a40e
commit eea3b1e427
19 changed files with 391 additions and 132 deletions

36
app/bootstrap.php Normal file
View File

@ -0,0 +1,36 @@
<?php
require __DIR__.'/../vendor/autoload.php';
/**
* Wrap everything in a closure to preserve global scope and return the
* application.
*/
return call_user_func(function () {
$app = null;
/**
* This closure will be used to require other init files with a clean
* scope, with only access to `$app`.
*/
$closure = function () use (&$app) {
require func_get_arg(0);
};
$files = array();
foreach (new DirectoryIterator(__FILE__ . '.d') as $file) {
if (!$file->isDot() && $file->isFile()) {
$files[] = $file->getPathname();
}
}
// Sort init files, order is important
sort($files);
foreach ($files as $file) {
$closure($file);
}
return $app;
});

View File

@ -0,0 +1,7 @@
<?php
use Gist\Application;
$app = Application::getInstance();
$app['root_path'] = __DIR__ . '/../..';

View File

@ -0,0 +1,9 @@
<?php
use Symfony\Component\Config\FileLocator;
$app['config.locator.path'] = $app['root_path'].'/app/config';
$app['config.locator'] = function ($app) {
return new FileLocator($app['config.locator.path']);
};

View File

@ -0,0 +1,12 @@
<?php
$app->error(function (Exception $e, $code) use ($app) {
return $app['twig']->render(
'error.html.twig',
array(
'code' => $code,
'name' => get_class($e),
'exception' => $e,
)
);
});

View File

@ -0,0 +1,14 @@
<?php
use Symfony\Component\Routing\Loader\YamlFileLoader;
$app['routing.file'] = 'routing.yml';
$app['routing.loader'] = function ($app) {
return new YamlFileLoader($app['config.locator']);
};
$app['routes'] = $app->extend('routes', function ($routes, $app) {
$routes->addCollection($app['routing.loader']->load($app['routing.file']));
return $routes;
});

View File

@ -0,0 +1,13 @@
<?php
use Silex\Provider\TwigServiceProvider;
$app->register(new TwigServiceProvider(), array(
'twig.path' => $app['root_path'].'/src/Gist/Resources/views',
));
$app->extend('twig', function ($twig, $app) {
$twig->addGlobal('web_path', '/');
return $twig;
});

View File

@ -0,0 +1,58 @@
<?php
use Silex\Provider\TranslationServiceProvider;
use Symfony\Component\HttpFoundation\AcceptHeader;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Translation\Loader\YamlFileLoader;
$app->register(new TranslationServiceProvider(), array(
'locale' => 'en',
'locale_fallback' => 'en',
'locales' => array('en', 'fr'), // Custom parameter, not Silex
));
$app['translator'] = $app->extend('translator', function ($translator, $app) {
$translator->addLoader('yaml', new YamlFileLoader());
foreach ($app['locales'] as $locale) {
$file = $app['root_path'].'/app/locales/'.$locale.'.yml';
if (is_file($file)) {
$translator->addResource('yaml', $file, $locale);
}
}
return $translator;
});
$app['routes'] = $app->extend('routes', function ($routes, $app) {
$routes->addPrefix('/{_locale}');
$routes->addDefaults(array('_locale' => $app['locale_fallbacks'][0]));
$routes->addRequirements(array('_locale' => implode('|', $app['locales'])));
return $routes;
});
/**
* Redirect home on right locale page, regarding of request accept locale or
* default fallback.
*/
$app->get('/', function (Request $request) use ($app) {
$accept = AcceptHeader::fromString($request->headers->get('Accept-Language'));
// Default locale fallback
$foundLocale = $app['translator']->getLocale();
foreach ($app['locales'] as $locale) {
if ($accept->has($locale)) {
$foundLocale = $locale;
break;
}
}
return new RedirectResponse($app['url_generator']->generate(
'home',
array('_locale' => $foundLocale)
));
});

3
app/config/routing.yml Normal file
View File

@ -0,0 +1,3 @@
home:
path: /
defaults: { _controller: Gist\Controller\HomeController::indexAction, _locale: en }

6
app/console Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env php
<?php
$app = require __DIR__.'/bootstrap.php';
$app['console']->run();

14
app/deploy Executable file
View File

@ -0,0 +1,14 @@
#!/bin/sh
cd "$(dirname "$0")/.."
deploy_preprod() {
rsync -avzoK --delete -e ssh * weblinuxtest@deblan.fr:/services/web/www/linux-test.deblan.org/project/
}
deploy_preprod_lan() {
rsync -avzoK --delete -e ssh * weblinuxtest@hinata:/services/web/www/linux-test.deblan.org/project/
}
([ -n "$1" ] && deploy_$1) || deploy_preprod

8
app/locales/en.yml Normal file
View File

@ -0,0 +1,8 @@
app:
title_prefix: '#!GIST - '
menu:
home:
title: 'Home'
about:
title: 'About'

0
app/locales/fr.yml Normal file
View File

View File

@ -1,5 +1,15 @@
{ {
"require": { "require": {
"geshi/geshi": "dev-master" "geshi/geshi": "dev-master",
"silex/silex": "dev-master",
"symfony/yaml": "~2.6",
"symfony/twig-bridge": "dev-master",
"symfony/translation": "dev-master",
"symfony/config": "2.8.x-dev"
},
"autoload": {
"psr-0": {
"": "src/"
}
} }
} }

22
src/Gist/Application.php Normal file
View File

@ -0,0 +1,22 @@
<?php
namespace Gist;
use Silex\Application as SilexApplication;
/**
* @deprecated The static version should be avoided, use DI instead.
*/
class Application extends SilexApplication
{
public static function getInstance()
{
static $app;
if (null === $app) {
$app = new static;
}
return $app;
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace Gist\Controller;
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
/**
* Class HomeController
* @author Simon Vieille
*/
class HomeController
{
public function indexAction(Request $request, Application $app)
{
return $app['twig']->render('Home/index.html.twig');
}
}

View File

@ -0,0 +1 @@
{% extends 'base.html.twig' %}

View File

@ -0,0 +1,139 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
{% block css %}
<link rel="stylesheet" href="{{ web_path }}components/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="{{ web_path }}app/css/bootstrap/bootstrap.min.css" />
<link rel="stylesheet" href="{{ web_path }}app/css/app.css" />
{% endblock %}
{% block metas %}
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
{% endblock %}
<title>{{ 'app.title_prefix'|trans }}{% block title %}{% endblock %}</title>
</head>
<body>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main-menu">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">#!GIST</a>
</div>
<div class="collapse navbar-collapse" id="main-menu">
<ul class="nav navbar-nav">
<li class="active">
<a href="{{ path('home') }}">
{{ 'app.menu.home.title'|trans }}
</a>
</li>
<li>
<a href="{{ path('home') }}">
{{ 'app.menu.about.title'|trans }}
</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container-fluid" id="container">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<input type="text" class="form-control" id="name" placeholder="Title">
</div>
<div class="panel-body">
<p class="text-primary">
<span class="glyphicon glyphicon-info-sign"></span>
En activant le chiffrement, le code déposé ne pourra pas être forké.
</p>
<div class="btn-toolbar">
<div class="btn-group" id="languages">
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
Language XML
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li>
<a href="html">HTML/XML</a>
</li>
<li>
<a href="css">CSS</a>
</li>
<li>
<a href="javascript">JAVASCRIPT</a>
</li>
<li>
<a href="php">PHP</a>
</li>
<li>
<a href="sql">SQL</a>
</li>
<li>
<a href="yaml">YAML</a>
</li>
<li>
<a href="perl">PERL</a>
</li>
<li>
<a href="c">C/C++</a>
</li>
<li>
<a href="asp">ASP</a>
</li>
<li>
<a href="python">PYTHON</a>
</li>
<li>
<a href="bash">BASH</a>
</li>
<li>
<a href="actionscript">ACTION SCRIPT</a>
</li>
<li>
<a href="texte">TEXT</a>
</li>
</ul>
</div>
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
Chiffrement : non
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li>
<a href="html">oui</a>
</li>
<li>
<a href="css">non</a>
</li>
</ul>
</div>
</div>
</div>
<p>
<textarea rows="10" id="code" class="form-control"></textarea>
</p>
<p>
<input type="submit" class="btn btn-primary" value="Envoyer">
</p>
</div>
</div>
</div>
</div>
{% block js %}
<script src="{{ web_path }}components/jquery/dist/jquery.min.js"></script>
<script src="{{ web_path }}components/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="{{ web_path }}components/select2-dist/dist/js/select2.full.min.js"></script>
<script src="{{ web_path }}app/js/app.js></script>
{% endblock %}
</div>
</body>
</html>

View File

@ -0,0 +1,15 @@
{% extends 'base.html.twig' %}
{% block title %}
Error {{ code }} - {{ name }}
{% endblock %}
{% block body %}
<h1>{{ name }}</h1>
<p><em>In file "{{ exception.file }}" at line {{ exception.line }}</em></p>
<p>{{ exception.message }}</p>
<h2>Stacktrace</h2>
<pre>{{ exception.traceAsString }}</pre>
{% endblock %}

View File

@ -1,131 +1,5 @@
<!DOCTYPE html> <?php
<html xmlns="http://www.w3.org/1999/xhtml">
<head> $app = require __DIR__.'/../app/bootstrap.php';
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="components/bootstrap/dist/css/bootstrap.min.css" /> $app->run();
<link rel="stylesheet" href="app/css/bootstrap/bootstrap.min.css" />
<link rel="stylesheet" href="app/css/app.css" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>GIST</title>
</head>
<body>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main-menu">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">#!GIST</a>
</div>
<div class="collapse navbar-collapse" id="main-menu">
<ul class="nav navbar-nav">
<li class="active">
<a href="#">
Home
<span class="sr-only">(current)</span>
</a>
</li>
<li>
<a href="#">About</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container-fluid" id="container">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<input type="text" class="form-control" id="name" placeholder="Title">
</div>
<div class="panel-body">
<p class="text-primary">
<span class="glyphicon glyphicon-info-sign"></span>
En activant le chiffrement, le code déposé ne pourra pas être forké.
</p>
<div class="btn-toolbar">
<div class="btn-group" id="languages">
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
Language XML
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li>
<a href="html">HTML/XML</a>
</li>
<li>
<a href="css">CSS</a>
</li>
<li>
<a href="javascript">JAVASCRIPT</a>
</li>
<li>
<a href="php">PHP</a>
</li>
<li>
<a href="sql">SQL</a>
</li>
<li>
<a href="yaml">YAML</a>
</li>
<li>
<a href="perl">PERL</a>
</li>
<li>
<a href="c">C/C++</a>
</li>
<li>
<a href="asp">ASP</a>
</li>
<li>
<a href="python">PYTHON</a>
</li>
<li>
<a href="bash">BASH</a>
</li>
<li>
<a href="actionscript">ACTION SCRIPT</a>
</li>
<li>
<a href="texte">TEXT</a>
</li>
</ul>
</div>
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
Chiffrement : non
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li>
<a href="html">oui</a>
</li>
<li>
<a href="css">non</a>
</li>
</ul>
</div>
</div>
</div>
<p>
<textarea rows="10" id="code" class="form-control"></textarea>
</p>
<p>
<input type="submit" class="btn btn-primary" value="Envoyer">
</p>
</div>
</div>
</div>
</div>
<script src="components/jquery/dist/jquery.min.js"></script>
<script src="components/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="components/select2-dist/dist/js/select2.full.min.js"></script>
<script src="app/js/app.js"></script>
</div>
</body>
</html>