Merge pull request #356 from gza/master

Add contextual Readme display
This commit is contained in:
Klaus Silveira
2014-09-02 17:05:55 -03:00
2 changed files with 9 additions and 5 deletions

View File

@@ -41,7 +41,7 @@ class TreeController implements ControllerProviderInterface
'breadcrumbs' => $breadcrumbs,
'branches' => $repository->getBranches(),
'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('commitishPath', $app['util.routing']->getCommitishPathRegex())

View File

@@ -164,22 +164,26 @@ class Repository
return false;
}
public function getReadme($repository, $branch = null)
public function getReadme($repository, $branch = null, $path = "")
{
$files = $repository->getTree($branch)->output();
if ($branch === null) {
$branch = $repository->getHead();
}
if ($path != "") $path = "$path/";
$files = $repository->getTree($path != "" ? "$branch:$path" : $branch)->output();
foreach ($files as $file) {
if (preg_match('/^readme*/i', $file['name'])) {
return array(
'filename' => $file['name'],
'content' => $repository->getBlob("$branch:\"{$file['name']}\"")->output()
'content' => $repository->getBlob("$branch:\"$path{$file['name']}\"")->output()
);
}
}
// No contextual readme, try to catch the main one if we are in deeper context
if ($path != "") return $this->getReadme($repository, $branch, "");
return array();
}