diff --git a/controllers/treeController.php b/controllers/treeController.php index fcdb99b..210e0ac 100644 --- a/controllers/treeController.php +++ b/controllers/treeController.php @@ -1,53 +1,17 @@ get('{repo}/', function($repo) use($app) { +$app->get('{repo}/tree/{branch}/{tree}/', $treeController = function($repo, $branch = '', $tree = '') use($app) { $repository = $app['git']->getRepository($app['git.repos'] . $repo); - $defaultBranch = $repository->getHead(); - $tree = $repository->getTree($defaultBranch); - - return $app['twig']->render('tree.twig', array( - 'page' => 'files', - 'files' => $tree->output(), - 'repo' => $repo, - 'branch' => $defaultBranch, - 'path' => '', - 'parent' => '', - 'breadcrumbs' => array(), - 'branches' => $repository->getBranches(), - 'tags' => $repository->getTags(), - 'readme' => $app['utils']->getReadme($repo, $defaultBranch), - )); -})->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); - - return $app['twig']->render('tree.twig', array( - 'page' => 'files', - 'files' => $tree->output(), - 'repo' => $repo, - 'branch' => $branch, - 'path' => '', - 'parent' => '', - 'breadcrumbs' => array(), - 'branches' => $repository->getBranches(), - 'tags' => $repository->getTags(), - 'readme' => $app['utils']->getReadme($repo, $branch), - )); -})->assert('repo', '[\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'/"); + if (!$branch) { + $branch = $repository->getHead(); + } + $files = $repository->getTree($tree ? "$branch:'$tree'/" : $branch); $breadcrumbs = $app['utils']->getBreadcrumbs($tree); + $parent = null; if (($slash = strrpos($tree, '/')) !== false) { $parent = substr($tree, 0, $slash); - } else { + } elseif (!empty($tree)) { $parent = ''; } @@ -56,14 +20,25 @@ $app->get('{repo}/tree/{branch}/{tree}/', function($repo, $branch, $tree) use($a 'files' => $files->output(), 'repo' => $repo, 'branch' => $branch, - 'path' => "$tree/", + 'path' => $tree ? $tree.'/' : $tree, 'parent' => $parent, 'breadcrumbs' => $breadcrumbs, 'branches' => $repository->getBranches(), 'tags' => $repository->getTags(), 'readme' => $app['utils']->getReadme($repo, $branch), )); -})->assert('tree', '.+') - ->assert('repo', '[\w-._]+') +})->assert('repo', '[\w-._]+') ->assert('branch', '[\w-._]+') - ->bind('tree_dir'); + ->assert('tree', '.+') + ->bind('tree'); + +$app->get('{repo}/{branch}/', function($repo, $branch) use($app, $treeController) { + return $treeController($repo, $branch); +})->assert('repo', '[\w-._]+') + ->assert('branch', '[\w-._]+') + ->bind('branch'); + +$app->get('{repo}/', function($repo) use($app, $treeController) { + return $treeController($repo); +})->assert('repo', '[\w-._]+') + ->bind('repository'); diff --git a/lib/Application/Utils.php b/lib/Application/Utils.php index a2643ba..9660c2e 100644 --- a/lib/Application/Utils.php +++ b/lib/Application/Utils.php @@ -24,6 +24,10 @@ class Utils */ public function getBreadcrumbs($spec) { + if (!$spec) { + return array(); + } + $paths = explode('/', $spec); foreach ($paths as $i => $path) { diff --git a/views/branch_menu.twig b/views/branch_menu.twig index 2d5f835..2809ab2 100644 --- a/views/branch_menu.twig +++ b/views/branch_menu.twig @@ -3,12 +3,12 @@
diff --git a/views/breadcrumb.twig b/views/breadcrumb.twig index 81c4e24..c7e954a 100644 --- a/views/breadcrumb.twig +++ b/views/breadcrumb.twig @@ -1,8 +1,8 @@