contextual readme management

This commit is contained in:
Guillaume Zitta
2013-07-29 18:00:37 +02:00
parent 2d6ccd0f1c
commit 1cae7513d4
2 changed files with 7 additions and 4 deletions

View File

@@ -41,7 +41,7 @@ class TreeController implements ControllerProviderInterface
'breadcrumbs' => $breadcrumbs, 'breadcrumbs' => $breadcrumbs,
'branches' => $repository->getBranches(), 'branches' => $repository->getBranches(),
'tags' => $repository->getTags(), 'tags' => $repository->getTags(),
'readme' => $app['util.repository']->getReadme($repository, $branch), 'readme' => $app['util.repository']->getReadme($repository, $branch, $tree ? "$tree" : ""),
)); ));
})->assert('repo', $app['util.routing']->getRepositoryRegex()) })->assert('repo', $app['util.routing']->getRepositoryRegex())
->assert('commitishPath', $app['util.routing']->getCommitishPathRegex()) ->assert('commitishPath', $app['util.routing']->getCommitishPathRegex())

View File

@@ -161,18 +161,21 @@ class Repository
return false; return false;
} }
public function getReadme($repository, $branch = null) public function getReadme($repository, $branch = null, $path = "")
{ {
$files = $repository->getTree($branch)->output();
if ($branch === null) { if ($branch === null) {
$branch = $repository->getHead(); $branch = $repository->getHead();
} }
if ($path != "") $path = "$path/";
$files = $repository->getTree($path != "" ? "$branch:$path" : $branch)->output();
foreach ($files as $file) { foreach ($files as $file) {
if (preg_match('/^readme*/i', $file['name'])) { if (preg_match('/^readme*/i', $file['name'])) {
return array( return array(
'filename' => $file['name'], 'filename' => $file['name'],
'content' => $repository->getBlob("$branch:\"{$file['name']}\"")->output() 'content' => $repository->getBlob("$branch:\"$path{$file['name']}\"")->output()
); );
} }
} }