1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-29 10:12:41 +01:00

Show README on repository screen in Diffusion

Summary:
  - Show README on the repository screen.
  - Move README to the bottom of the page for both repository and browse screens.
  - Support "README.rainbow".

Test Plan: Looked at repository, browse screens. Made a "README.rainbow".

Reviewers: btrahan, vrana, jungejason

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T1104

Differential Revision: https://secure.phabricator.com/D2336
This commit is contained in:
epriestley 2012-04-30 07:47:41 -07:00
parent 6fd99e287b
commit 321b776148
5 changed files with 86 additions and 31 deletions

View file

@ -81,34 +81,6 @@ final class DiffusionBrowseController extends DiffusionController {
$phids = array_keys($phids); $phids = array_keys($phids);
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
if ($readme) {
$readme_request = DiffusionRequest::newFromDictionary(
array(
'repository' => $drequest->getRepository(),
'commit' => $drequest->getStableCommitName(),
'path' => $readme->getFullPath(),
));
$content_query = DiffusionFileContentQuery::newFromDiffusionRequest(
$readme_request);
$content_query->loadFileContent();
$readme_content = $content_query->getRawData();
if (preg_match('/.txt$/', $readme->getPath())) {
$readme_content = phutil_escape_html($readme_content);
$readme_content = nl2br($readme_content);
} else {
// Markup extensionless files as remarkup so we get links and such.
$readme_content = $this->markupText($readme_content);
}
$readme_panel = new AphrontPanelView();
$readme_panel->setHeader('README');
$readme_panel->appendChild($readme_content);
$content[] = $readme_panel;
}
$browse_table = new DiffusionBrowseTableView(); $browse_table = new DiffusionBrowseTableView();
$browse_table->setDiffusionRequest($drequest); $browse_table->setDiffusionRequest($drequest);
$browse_table->setHandles($handles); $browse_table->setHandles($handles);
@ -122,6 +94,16 @@ final class DiffusionBrowseController extends DiffusionController {
$content[] = $this->buildOpenRevisions(); $content[] = $this->buildOpenRevisions();
$readme_content = $browse_query->renderReadme($results);
if ($readme_content) {
$readme_panel = new AphrontPanelView();
$readme_panel->setHeader('README');
$readme_panel->appendChild($readme_content);
$content[] = $readme_panel;
}
$nav = $this->buildSideNav('browse', false); $nav = $this->buildSideNav('browse', false);
$nav->appendChild($content); $nav->appendChild($content);

View file

@ -9,8 +9,6 @@
phutil_require_module('phabricator', 'applications/diffusion/controller/base'); phutil_require_module('phabricator', 'applications/diffusion/controller/base');
phutil_require_module('phabricator', 'applications/diffusion/controller/file'); phutil_require_module('phabricator', 'applications/diffusion/controller/file');
phutil_require_module('phabricator', 'applications/diffusion/query/browse/base'); phutil_require_module('phabricator', 'applications/diffusion/query/browse/base');
phutil_require_module('phabricator', 'applications/diffusion/query/filecontent/base');
phutil_require_module('phabricator', 'applications/diffusion/request/base');
phutil_require_module('phabricator', 'applications/diffusion/view/browsetable'); phutil_require_module('phabricator', 'applications/diffusion/view/browsetable');
phutil_require_module('phabricator', 'applications/diffusion/view/emptyresult'); phutil_require_module('phabricator', 'applications/diffusion/view/emptyresult');
phutil_require_module('phabricator', 'applications/markup/engine'); phutil_require_module('phabricator', 'applications/markup/engine');

View file

@ -110,6 +110,14 @@ final class DiffusionRepositoryController extends DiffusionController {
$content[] = $branch_panel; $content[] = $branch_panel;
} }
$readme = $browse_query->renderReadme($browse_results);
if ($readme) {
$panel = new AphrontPanelView();
$panel->setHeader('README');
$panel->appendChild($readme);
$content[] = $panel;
}
return $this->buildStandardPageResponse( return $this->buildStandardPageResponse(
$content, $content,
array( array(

View file

@ -1,7 +1,7 @@
<?php <?php
/* /*
* Copyright 2011 Facebook, Inc. * Copyright 2012 Facebook, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -93,5 +93,66 @@ abstract class DiffusionBrowseQuery {
return $this; return $this;
} }
final public function renderReadme(array $results) {
$drequest = $this->getRequest();
$readme = null;
foreach ($results as $result) {
$path = $result->getPath();
if (preg_match('/^readme(|\.txt|\.remarkup|\.rainbow)$/i', $path)) {
$readme = $result;
break;
}
}
if (!$readme) {
return null;
}
$readme_request = DiffusionRequest::newFromDictionary(
array(
'repository' => $drequest->getRepository(),
'commit' => $drequest->getStableCommitName(),
'path' => $readme->getFullPath(),
));
$content_query = DiffusionFileContentQuery::newFromDiffusionRequest(
$readme_request);
$content_query->loadFileContent();
$readme_content = $content_query->getRawData();
if (preg_match('/\\.txt$/', $readme->getPath())) {
$readme_content = phutil_escape_html($readme_content);
$readme_content = nl2br($readme_content);
$class = null;
} else if (preg_match('/\\.rainbow$/', $readme->getPath())) {
$highlighter = new PhutilRainbowSyntaxHighlighter();
$readme_content = $highlighter
->getHighlightFuture($readme_content)
->resolve();
$readme_content = nl2br($readme_content);
require_celerity_resource('syntax-highlighting-css');
$class = 'remarkup-code';
} else {
// Markup extensionless files as remarkup so we get links and such.
$engine = PhabricatorMarkupEngine::newDiffusionMarkupEngine();
$readme_content = $engine->markupText($readme_content);
$class = 'phabricator-remarkup';
}
$readme_content = phutil_render_tag(
'div',
array(
'class' => $class,
),
$readme_content);
return $readme_content;
}
abstract protected function executeQuery(); abstract protected function executeQuery();
} }

View file

@ -6,8 +6,14 @@
phutil_require_module('phabricator', 'applications/diffusion/query/filecontent/base');
phutil_require_module('phabricator', 'applications/diffusion/request/base');
phutil_require_module('phabricator', 'applications/markup/engine');
phutil_require_module('phabricator', 'applications/repository/constants/repositorytype'); phutil_require_module('phabricator', 'applications/repository/constants/repositorytype');
phutil_require_module('phabricator', 'infrastructure/celerity/api');
phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'markup/syntax/highlighter/rainbow');
phutil_require_module('phutil', 'symbols'); phutil_require_module('phutil', 'symbols');