mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 00:32:42 +01:00
Add an abstract "Text" document engine and a "Source" document engine
Summary: Ref T13105. Allow normal text files to be rendered as documents, and add a "source code" rendering engine. Test Plan: Viewed some source code. Reviewers: mydeveloperday Reviewed By: mydeveloperday Maniphest Tasks: T13105 Differential Revision: https://secure.phabricator.com/D19254
This commit is contained in:
parent
cbf3d3c371
commit
d2727d24da
6 changed files with 82 additions and 19 deletions
|
@ -9,7 +9,7 @@ return array(
|
|||
'names' => array(
|
||||
'conpherence.pkg.css' => 'e68cf1fa',
|
||||
'conpherence.pkg.js' => '15191c65',
|
||||
'core.pkg.css' => '7daac340',
|
||||
'core.pkg.css' => 'da541195',
|
||||
'core.pkg.js' => 'b9b4a943',
|
||||
'differential.pkg.css' => '113e692c',
|
||||
'differential.pkg.js' => 'f6d809c0',
|
||||
|
@ -120,7 +120,7 @@ return array(
|
|||
'rsrc/css/font/font-lato.css' => 'c7ccd872',
|
||||
'rsrc/css/font/phui-font-icon-base.css' => '870a7360',
|
||||
'rsrc/css/layout/phabricator-filetree-view.css' => 'b912ad97',
|
||||
'rsrc/css/layout/phabricator-source-code-view.css' => '926ced2d',
|
||||
'rsrc/css/layout/phabricator-source-code-view.css' => '31ee3c83',
|
||||
'rsrc/css/phui/button/phui-button-bar.css' => 'f1ff5494',
|
||||
'rsrc/css/phui/button/phui-button-simple.css' => '8e1baf68',
|
||||
'rsrc/css/phui/button/phui-button.css' => '1863cc6e',
|
||||
|
@ -168,7 +168,7 @@ return array(
|
|||
'rsrc/css/phui/phui-object-box.css' => '9cff003c',
|
||||
'rsrc/css/phui/phui-pager.css' => 'edcbc226',
|
||||
'rsrc/css/phui/phui-pinboard-view.css' => '2495140e',
|
||||
'rsrc/css/phui/phui-property-list-view.css' => '871f6815',
|
||||
'rsrc/css/phui/phui-property-list-view.css' => '54c071ed',
|
||||
'rsrc/css/phui/phui-remarkup-preview.css' => '54a34863',
|
||||
'rsrc/css/phui/phui-segment-bar-view.css' => 'b1d1b892',
|
||||
'rsrc/css/phui/phui-spacing.css' => '042804d6',
|
||||
|
@ -784,7 +784,7 @@ return array(
|
|||
'phabricator-search-results-css' => '505dd8cf',
|
||||
'phabricator-shaped-request' => '7cbe244b',
|
||||
'phabricator-slowvote-css' => 'a94b7230',
|
||||
'phabricator-source-code-view-css' => '926ced2d',
|
||||
'phabricator-source-code-view-css' => '31ee3c83',
|
||||
'phabricator-standard-page-view' => '34ee718b',
|
||||
'phabricator-textareautils' => '320810c8',
|
||||
'phabricator-title' => '485aaa6c',
|
||||
|
@ -850,7 +850,7 @@ return array(
|
|||
'phui-oi-simple-ui-css' => 'a8beebea',
|
||||
'phui-pager-css' => 'edcbc226',
|
||||
'phui-pinboard-view-css' => '2495140e',
|
||||
'phui-property-list-view-css' => '871f6815',
|
||||
'phui-property-list-view-css' => '54c071ed',
|
||||
'phui-remarkup-preview-css' => '54a34863',
|
||||
'phui-segment-bar-view-css' => 'b1d1b892',
|
||||
'phui-spacing-css' => '042804d6',
|
||||
|
|
|
@ -4222,6 +4222,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorSlug' => 'infrastructure/util/PhabricatorSlug.php',
|
||||
'PhabricatorSlugTestCase' => 'infrastructure/util/__tests__/PhabricatorSlugTestCase.php',
|
||||
'PhabricatorSourceCodeView' => 'view/layout/PhabricatorSourceCodeView.php',
|
||||
'PhabricatorSourceDocumentEngine' => 'applications/files/document/PhabricatorSourceDocumentEngine.php',
|
||||
'PhabricatorSpaceEditField' => 'applications/transactions/editfield/PhabricatorSpaceEditField.php',
|
||||
'PhabricatorSpacesApplication' => 'applications/spaces/application/PhabricatorSpacesApplication.php',
|
||||
'PhabricatorSpacesArchiveController' => 'applications/spaces/controller/PhabricatorSpacesArchiveController.php',
|
||||
|
@ -4363,6 +4364,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorTestWorker' => 'infrastructure/daemon/workers/__tests__/PhabricatorTestWorker.php',
|
||||
'PhabricatorTextAreaEditField' => 'applications/transactions/editfield/PhabricatorTextAreaEditField.php',
|
||||
'PhabricatorTextConfigType' => 'applications/config/type/PhabricatorTextConfigType.php',
|
||||
'PhabricatorTextDocumentEngine' => 'applications/files/document/PhabricatorTextDocumentEngine.php',
|
||||
'PhabricatorTextEditField' => 'applications/transactions/editfield/PhabricatorTextEditField.php',
|
||||
'PhabricatorTextExportFormat' => 'infrastructure/export/format/PhabricatorTextExportFormat.php',
|
||||
'PhabricatorTextListConfigType' => 'applications/config/type/PhabricatorTextListConfigType.php',
|
||||
|
@ -10041,6 +10043,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorSlug' => 'Phobject',
|
||||
'PhabricatorSlugTestCase' => 'PhabricatorTestCase',
|
||||
'PhabricatorSourceCodeView' => 'AphrontView',
|
||||
'PhabricatorSourceDocumentEngine' => 'PhabricatorTextDocumentEngine',
|
||||
'PhabricatorSpaceEditField' => 'PhabricatorEditField',
|
||||
'PhabricatorSpacesApplication' => 'PhabricatorApplication',
|
||||
'PhabricatorSpacesArchiveController' => 'PhabricatorSpacesController',
|
||||
|
@ -10188,6 +10191,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorTestWorker' => 'PhabricatorWorker',
|
||||
'PhabricatorTextAreaEditField' => 'PhabricatorEditField',
|
||||
'PhabricatorTextConfigType' => 'PhabricatorConfigType',
|
||||
'PhabricatorTextDocumentEngine' => 'PhabricatorDocumentEngine',
|
||||
'PhabricatorTextEditField' => 'PhabricatorEditField',
|
||||
'PhabricatorTextExportFormat' => 'PhabricatorExportFormat',
|
||||
'PhabricatorTextListConfigType' => 'PhabricatorTextConfigType',
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorSourceDocumentEngine
|
||||
extends PhabricatorTextDocumentEngine {
|
||||
|
||||
const ENGINEKEY = 'source';
|
||||
|
||||
public function getViewAsLabel(PhabricatorDocumentRef $ref) {
|
||||
return pht('View as Source');
|
||||
}
|
||||
|
||||
protected function getDocumentIconIcon(PhabricatorDocumentRef $ref) {
|
||||
return 'fa-code';
|
||||
}
|
||||
|
||||
protected function getContentScore(PhabricatorDocumentRef $ref) {
|
||||
return 1500;
|
||||
}
|
||||
|
||||
protected function newDocumentContent(PhabricatorDocumentRef $ref) {
|
||||
$content = $this->loadTextData($ref);
|
||||
|
||||
$content = PhabricatorSyntaxHighlighter::highlightWithFilename(
|
||||
$ref->getName(),
|
||||
$content);
|
||||
|
||||
return $this->newTextDocumentContent($content);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
abstract class PhabricatorTextDocumentEngine
|
||||
extends PhabricatorDocumentEngine {
|
||||
|
||||
protected function canRenderDocumentType(PhabricatorDocumentRef $ref) {
|
||||
return $ref->isProbablyText();
|
||||
}
|
||||
|
||||
protected function newTextDocumentContent($content) {
|
||||
$lines = phutil_split_lines($content);
|
||||
|
||||
$view = id(new PhabricatorSourceCodeView())
|
||||
->setLines($lines)
|
||||
->disableHighlightOnClick();
|
||||
|
||||
$container = phutil_tag(
|
||||
'div',
|
||||
array(
|
||||
'class' => 'document-engine-text',
|
||||
),
|
||||
$view);
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
protected function loadTextData(PhabricatorDocumentRef $ref) {
|
||||
$content = $ref->loadData();
|
||||
$content = phutil_utf8ize($content);
|
||||
return $content;
|
||||
}
|
||||
|
||||
}
|
|
@ -14,14 +14,6 @@
|
|||
margin-left: 8px;
|
||||
}
|
||||
|
||||
.phabricator-source-code-view tr:first-child * {
|
||||
padding-top: 8px;
|
||||
}
|
||||
|
||||
.phabricator-source-code-view tr:last-child * {
|
||||
padding-bottom: 8px;
|
||||
}
|
||||
|
||||
.phabricator-source-code {
|
||||
white-space: pre-wrap;
|
||||
padding: 2px 8px 1px;
|
||||
|
@ -45,12 +37,16 @@
|
|||
white-space: nowrap;
|
||||
}
|
||||
|
||||
th.phabricator-source-line a {
|
||||
color: {$darkbluetext};
|
||||
th.phabricator-source-line a,
|
||||
th.phabricator-source-line span {
|
||||
display: block;
|
||||
padding: 2px 6px 1px 12px;
|
||||
}
|
||||
|
||||
th.phabricator-source-line a {
|
||||
color: {$darkbluetext};
|
||||
}
|
||||
|
||||
th.phabricator-source-line a:hover {
|
||||
background: {$paste.border};
|
||||
text-decoration: none;
|
||||
|
@ -60,10 +56,6 @@ th.phabricator-source-line a:hover {
|
|||
background: {$paste.highlight};
|
||||
}
|
||||
|
||||
.phabricator-source-highlight th.phabricator-source-line {
|
||||
background: {$paste.border};
|
||||
}
|
||||
|
||||
.phabricator-source-code-summary {
|
||||
padding-bottom: 8px;
|
||||
}
|
||||
|
|
|
@ -258,6 +258,10 @@ div.phui-property-list-stacked .phui-property-list-properties
|
|||
text-align: left;
|
||||
}
|
||||
|
||||
.document-engine-text .phabricator-source-code-container {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.document-engine-jupyter {
|
||||
overflow: hidden;
|
||||
margin: 20px;
|
||||
|
|
Loading…
Reference in a new issue