diff --git a/composer.json b/composer.json index 4cf0bc0..f14c110 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,10 @@ { "require": { "silex/silex": "1.0.*", - "twig/twig": "1.8.*" - }, + "twig/twig": "1.8.*", + "symfony/twig-bridge": "2.1.*" + }, + "minimum-stability": "dev", "autoload": { "psr-0": { "Application": "lib/", diff --git a/composer.lock b/composer.lock index 40dda12..0b528b5 100644 --- a/composer.lock +++ b/composer.lock @@ -1,5 +1,5 @@ { - "hash": "3a86b6a3e837b125e3cebc503fd8cf38", + "hash": "8909d5f3ac695303e7845fe5cb0658ad", "packages": [ { "package": "pimple/pimple", @@ -22,8 +22,8 @@ { "package": "silex/silex", "version": "dev-master", - "source-reference": "13eb2ba916e39d5b8b1d054aaa441cf8e1004d85", - "commit-date": "1341343086" + "source-reference": "23dc19c334e2f74ec4de037568f5426bceaff421", + "commit-date": "1341597562" }, { "package": "symfony/event-dispatcher", @@ -74,16 +74,20 @@ "commit-date": "1341312726" }, { - "package": "twig/twig", + "package": "symfony/twig-bridge", "version": "dev-master", - "alias-pretty-version": "1.8.x-dev", - "alias-version": "1.8.9999999.9999999-dev" + "alias-pretty-version": "2.1.x-dev", + "alias-version": "2.1.9999999.9999999-dev" + }, + { + "package": "symfony/twig-bridge", + "version": "dev-master", + "source-reference": "2a577b6cf0fe32f383acf4a972c1d5d8f48ae1e2", + "commit-date": "1340549862" }, { "package": "twig/twig", - "version": "dev-master", - "source-reference": "73da773aaad0f97f2e967ec8241b8adf7b1e03d2", - "commit-date": "1340890758" + "version": "v1.8.3" } ], "packages-dev": null, diff --git a/config.ini-example b/config.ini-example index fc99be3..9ae80ef 100644 --- a/config.ini-example +++ b/config.ini-example @@ -6,7 +6,6 @@ repositories = '/var/www/projects/' ; Path to your repositories ; hidden[] = '/var/www/projects/BetaTest' [app] -baseurl = 'http://localhost/git' ; Base URL of the application ; If you need to specify custom filetypes for certain extensions, do this here [filetypes] diff --git a/controllers/blobController.php b/controllers/blobController.php index 822fbed..01c0c4e 100644 --- a/controllers/blobController.php +++ b/controllers/blobController.php @@ -3,11 +3,10 @@ $app->get('{repo}/blob/{branch}/{file}/', function($repo, $branch, $file) use($app) { $repository = $app['git']->getRepository($app['git.repos'] . $repo); $blob = $repository->getBlob("$branch:'$file'"); - $breadcrumbs = $app['utils']->getBreadcrumbs("$repo/tree/$branch/$file"); + $breadcrumbs = $app['utils']->getBreadcrumbs($file); $fileType = $app['utils']->getFileType($file); return $app['twig']->render('file.twig', array( - 'baseurl' => $app['baseurl'], 'page' => 'files', 'file' => $file, 'fileType' => $fileType, @@ -20,7 +19,8 @@ $app->get('{repo}/blob/{branch}/{file}/', function($repo, $branch, $file) use($a )); })->assert('file', '.+') ->assert('repo', '[\w-._]+') - ->assert('branch', '[\w-._]+'); + ->assert('branch', '[\w-._]+') + ->bind('blob'); $app->get('{repo}/raw/{branch}/{file}', function($repo, $branch, $file) use($app) { $repository = $app['git']->getRepository($app['git.repos'] . $repo); @@ -29,4 +29,5 @@ $app->get('{repo}/raw/{branch}/{file}', function($repo, $branch, $file) use($app return new Symfony\Component\HttpFoundation\Response($blob, 200, array('Content-Type' => 'text/plain')); })->assert('file', '.+') ->assert('repo', '[\w-._]+') - ->assert('branch', '[\w-._]+'); + ->assert('branch', '[\w-._]+') + ->bind('blob_raw'); diff --git a/controllers/commitController.php b/controllers/commitController.php index 0427c68..beadfac 100644 --- a/controllers/commitController.php +++ b/controllers/commitController.php @@ -12,7 +12,6 @@ $app->get('{repo}/commits/{branch}', function($repo, $branch) use($app) { } return $app['twig']->render('commits.twig', array( - 'baseurl' => $app['baseurl'], 'page' => 'commits', 'pager' => $pager, 'repo' => $repo, @@ -23,7 +22,8 @@ $app->get('{repo}/commits/{branch}', function($repo, $branch) use($app) { )); })->assert('repo', '[\w-._]+') ->assert('branch', '[\w-._]+') - ->value('branch', 'master'); + ->value('branch', 'master') + ->bind('commits'); $app->get('{repo}/commits/{branch}/{file}/', function($repo, $branch, $file) use($app) { $repository = $app['git']->getRepository($app['git.repos'] . $repo); @@ -37,7 +37,6 @@ $app->get('{repo}/commits/{branch}/{file}/', function($repo, $branch, $file) use } return $app['twig']->render('commits.twig', array( - 'baseurl' => $app['baseurl'], 'page' => 'commits', 'pager' => $pager, 'repo' => $repo, @@ -55,21 +54,20 @@ $app->get('{repo}/commit/{commit}/', function($repo, $commit) use($app) { $commit = $repository->getCommit($commit); return $app['twig']->render('commit.twig', array( - 'baseurl' => $app['baseurl'], 'page' => 'commits', 'branch' => 'master', 'repo' => $repo, 'commit' => $commit, )); })->assert('repo', '[\w-._]+') - ->assert('commit', '[a-f0-9]+'); + ->assert('commit', '[a-f0-9]+') + ->bind('commit'); $app->get('{repo}/blame/{branch}/{file}/', function($repo, $branch, $file) use($app) { $repository = $app['git']->getRepository($app['git.repos'] . $repo); $blames = $repository->getBlame("$branch -- $file"); return $app['twig']->render('blame.twig', array( - 'baseurl' => $app['baseurl'], 'page' => 'commits', 'file' => $file, 'repo' => $repo, @@ -80,4 +78,5 @@ $app->get('{repo}/blame/{branch}/{file}/', function($repo, $branch, $file) use($ )); })->assert('repo', '[\w-._]+') ->assert('file', '.+') - ->assert('branch', '[\w-._]+'); + ->assert('branch', '[\w-._]+') + ->bind('blame'); diff --git a/controllers/indexController.php b/controllers/indexController.php index df63f5b..cb85902 100644 --- a/controllers/indexController.php +++ b/controllers/indexController.php @@ -4,7 +4,6 @@ $app->get('/', function() use($app) { $repositories = $app['git']->getRepositories($app['git.repos']); return $app['twig']->render('index.twig', array( - 'baseurl' => $app['baseurl'], 'repositories' => $repositories, )); -}); \ No newline at end of file +})->bind('homepage'); diff --git a/controllers/rssController.php b/controllers/rssController.php index 55ebb29..00542eb 100644 --- a/controllers/rssController.php +++ b/controllers/rssController.php @@ -5,7 +5,6 @@ $app->get('{repo}/{branch}/rss/', function($repo, $branch) use($app) { $commits = $repository->getCommits($branch); $html = $app['twig']->render('rss.twig', array( - 'baseurl' => $app['baseurl'], 'repo' => $repo, 'branch' => $branch, 'commits' => $commits, @@ -13,4 +12,5 @@ $app->get('{repo}/{branch}/rss/', function($repo, $branch) use($app) { return new Symfony\Component\HttpFoundation\Response($html, 200, array('Content-Type' => 'application/rss+xml')); })->assert('repo', '[\w-._]+') - ->assert('branch', '[\w-._]+'); \ No newline at end of file + ->assert('branch', '[\w-._]+') + ->bind('rss'); \ No newline at end of file diff --git a/controllers/statsController.php b/controllers/statsController.php index ac41f2a..1058c07 100644 --- a/controllers/statsController.php +++ b/controllers/statsController.php @@ -6,7 +6,6 @@ $app->get('{repo}/stats/{branch}', function($repo, $branch) use($app) { $authors = $repository->getAuthorStatistics(); return $app['twig']->render('stats.twig', array( - 'baseurl' => $app['baseurl'], 'page' => 'stats', 'repo' => $repo, 'branch' => $branch, @@ -17,4 +16,5 @@ $app->get('{repo}/stats/{branch}', function($repo, $branch) use($app) { )); })->assert('repo', '[\w-._]+') ->assert('branch', '[\w-._]+') - ->value('branch', 'master'); \ No newline at end of file + ->value('branch', 'master') + ->bind('stats'); diff --git a/controllers/treeController.php b/controllers/treeController.php index bb470cc..fcdb99b 100644 --- a/controllers/treeController.php +++ b/controllers/treeController.php @@ -4,57 +4,54 @@ $app->get('{repo}/', function($repo) use($app) { $repository = $app['git']->getRepository($app['git.repos'] . $repo); $defaultBranch = $repository->getHead(); $tree = $repository->getTree($defaultBranch); - $breadcrumbs = $app['utils']->getBreadcrumbs("$repo/"); return $app['twig']->render('tree.twig', array( - 'baseurl' => $app['baseurl'], 'page' => 'files', 'files' => $tree->output(), 'repo' => $repo, 'branch' => $defaultBranch, 'path' => '', 'parent' => '', - 'breadcrumbs' => $breadcrumbs, + 'breadcrumbs' => array(), 'branches' => $repository->getBranches(), 'tags' => $repository->getTags(), 'readme' => $app['utils']->getReadme($repo, $defaultBranch), )); -})->assert('repo', '[\w-._]+'); +})->assert('repo', '[\w-._]+') + ->bind('repository'); $app->get('{repo}/tree/{branch}/', function($repo, $branch) use($app) { $repository = $app['git']->getRepository($app['git.repos'] . $repo); $tree = $repository->getTree($branch); - $breadcrumbs = $app['utils']->getBreadcrumbs("$repo/"); return $app['twig']->render('tree.twig', array( - 'baseurl' => $app['baseurl'], 'page' => 'files', 'files' => $tree->output(), 'repo' => $repo, 'branch' => $branch, 'path' => '', 'parent' => '', - 'breadcrumbs' => $breadcrumbs, + 'breadcrumbs' => array(), 'branches' => $repository->getBranches(), 'tags' => $repository->getTags(), 'readme' => $app['utils']->getReadme($repo, $branch), )); })->assert('repo', '[\w-._]+') - ->assert('branch', '[\w-._]+'); + ->assert('branch', '[\w-._]+') + ->bind('tree'); $app->get('{repo}/tree/{branch}/{tree}/', function($repo, $branch, $tree) use($app) { $repository = $app['git']->getRepository($app['git.repos'] . $repo); $files = $repository->getTree("$branch:'$tree'/"); - $breadcrumbs = $app['utils']->getBreadcrumbs("$repo/tree/$branch/$tree"); + $breadcrumbs = $app['utils']->getBreadcrumbs($tree); if (($slash = strrpos($tree, '/')) !== false) { - $parent = '/' . substr($tree, 0, $slash); + $parent = substr($tree, 0, $slash); } else { - $parent = '/'; + $parent = ''; } return $app['twig']->render('tree.twig', array( - 'baseurl' => $app['baseurl'], 'page' => 'files', 'files' => $files->output(), 'repo' => $repo, @@ -64,7 +61,9 @@ $app->get('{repo}/tree/{branch}/{tree}/', function($repo, $branch, $tree) use($a 'breadcrumbs' => $breadcrumbs, 'branches' => $repository->getBranches(), 'tags' => $repository->getTags(), + 'readme' => $app['utils']->getReadme($repo, $branch), )); })->assert('tree', '.+') ->assert('repo', '[\w-._]+') - ->assert('branch', '[\w-._]+'); + ->assert('branch', '[\w-._]+') + ->bind('tree_dir'); diff --git a/index.php b/index.php index a19d943..6543e74 100644 --- a/index.php +++ b/index.php @@ -14,7 +14,6 @@ if (empty($config['git']['repositories']) || !is_dir($config['git']['repositorie require 'vendor/autoload.php'; $app = new Silex\Application(); -$app['baseurl'] = rtrim($config['app']['baseurl'], '/'); $app['filetypes'] = $config['filetypes']; $app['hidden'] = isset($config['git']['hidden']) ? $config['git']['hidden'] : array(); $config['git']['repositories'] = rtrim($config['git']['repositories'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; @@ -29,9 +28,14 @@ $app->register(new Git\GitServiceProvider(), array( 'git.repos' => $config['git']['repositories'], )); $app->register(new Application\UtilsServiceProvider()); +$app->register(new Silex\Provider\UrlGeneratorServiceProvider()); -// Add the md5() function to Twig scope -$app['twig']->addFilter('md5', new Twig_Filter_Function('md5')); +$app['twig'] = $app->share($app->extend('twig', function($twig, $app) { + // Add the md5() function to Twig scope + $twig->addFilter('md5', new Twig_Filter_Function('md5')); + + return $twig; +})); // Load controllers include 'controllers/indexController.php'; @@ -44,8 +48,7 @@ include 'controllers/rssController.php'; // Error handling $app->error(function (\Exception $e, $code) use ($app) { return $app['twig']->render('error.twig', array( - 'baseurl' => $app['baseurl'], - 'message' => $e->getMessage(), + 'message' => $e->getMessage(), )); }); diff --git a/lib/Application/Utils.php b/lib/Application/Utils.php index 218f4a6..1c2bab6 100644 --- a/lib/Application/Utils.php +++ b/lib/Application/Utils.php @@ -29,16 +29,11 @@ class Utils foreach ($paths as $path) { $dir['dir'] = $path; - $dir['path'] = "$last/$path"; + $dir['path'] = "$last$path"; $breadcrumbs[] = $dir; - $last .= '/' . $path; + $last .= $path . '/'; } - if (isset($paths[2])) { - $breadcrumbs[0]['path'] .= '/' . $paths[1] . '/' . $paths[2]; - } - - unset($breadcrumbs[1], $breadcrumbs[2]); return $breadcrumbs; } diff --git a/views/blame.twig b/views/blame.twig index 390053e..fdf5845 100644 --- a/views/blame.twig +++ b/views/blame.twig @@ -12,7 +12,7 @@ @@ -23,7 +23,7 @@ {% for blame in blames %} - + {% endfor %} diff --git a/views/branch_menu.twig b/views/branch_menu.twig index 4db2d52..2d5f835 100644 --- a/views/branch_menu.twig +++ b/views/branch_menu.twig @@ -3,12 +3,12 @@ diff --git a/views/commit.twig b/views/commit.twig index da2146d..c341864 100644 --- a/views/commit.twig +++ b/views/commit.twig @@ -12,13 +12,13 @@
- Browse code + Browse code

{{ commit.getMessage }}

@@ -39,7 +39,7 @@
diff --git a/views/commits.twig b/views/commits.twig index ce511a4..fb41de9 100644 --- a/views/commits.twig +++ b/views/commits.twig @@ -13,7 +13,7 @@
@@ -29,7 +29,7 @@ diff --git a/views/file.twig b/views/file.twig index b624e84..b43c2a0 100644 --- a/views/file.twig +++ b/views/file.twig @@ -13,13 +13,10 @@ @@ -28,13 +25,13 @@
- Raw - Blame - History + Raw + Blame + History
{% if fileType == 'image' %} -
{{ file }}
+
{{ file }}
{% else %}
{{ blob }}
{% endif %} diff --git a/views/index.twig b/views/index.twig index dc13164..810bb56 100644 --- a/views/index.twig +++ b/views/index.twig @@ -9,8 +9,8 @@ {% for repository in repositories %}
- {{ repository.name }} - + {{ repository.name }} +

{{ repository.description }}

diff --git a/views/layout.twig b/views/layout.twig index 57535d0..9addf44 100644 --- a/views/layout.twig +++ b/views/layout.twig @@ -3,18 +3,18 @@ {% block title %}Welcome!{% endblock %} - + {% block body %}{% endblock %} - - - - - + + + + + diff --git a/views/menu.twig b/views/menu.twig index 658ef8f..3d5a89e 100644 --- a/views/menu.twig +++ b/views/menu.twig @@ -1,5 +1,5 @@ \ No newline at end of file diff --git a/views/navigation.twig b/views/navigation.twig index 40c2b25..7c0b197 100644 --- a/views/navigation.twig +++ b/views/navigation.twig @@ -6,7 +6,7 @@ - GitList + GitList diff --git a/views/tree.twig b/views/tree.twig index 2a3eddc..b267742 100644 --- a/views/tree.twig +++ b/views/tree.twig @@ -13,15 +13,12 @@
{{ blame.commit }}{{ blame.commit }}
{{ blame.line }}
- View {{ item.getShortHash }} + View {{ item.getShortHash }}

{{ item.getMessage }}

{{ item.getAuthor.getName }} authored in {{ item.getDate | date('d/m/Y \\a\\t H:i:s') }}
@@ -35,14 +32,20 @@ {% if parent is not empty %} - + {% endif %} {% for file in files %} - +
.. ..
{{ file.name }} {{ file.name }} {{ file.mode }} {% if file.size %}{{ (file.size / 1024) | number_format }} kb{% endif %}