From d2727d24da6e3142fee64ec9edbdcba9fa5dc357 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 23 Mar 2018 07:29:28 -0700 Subject: [PATCH] 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 --- resources/celerity/map.php | 10 +++--- src/__phutil_library_map__.php | 4 +++ .../PhabricatorSourceDocumentEngine.php | 30 +++++++++++++++++ .../PhabricatorTextDocumentEngine.php | 33 +++++++++++++++++++ .../layout/phabricator-source-code-view.css | 20 ++++------- .../rsrc/css/phui/phui-property-list-view.css | 4 +++ 6 files changed, 82 insertions(+), 19 deletions(-) create mode 100644 src/applications/files/document/PhabricatorSourceDocumentEngine.php create mode 100644 src/applications/files/document/PhabricatorTextDocumentEngine.php diff --git a/resources/celerity/map.php b/resources/celerity/map.php index 231c7fe5da..798f961f90 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -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', diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index a7b85ba4c5..0e2ff3f0fa 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/applications/files/document/PhabricatorSourceDocumentEngine.php b/src/applications/files/document/PhabricatorSourceDocumentEngine.php new file mode 100644 index 0000000000..1c3e54575a --- /dev/null +++ b/src/applications/files/document/PhabricatorSourceDocumentEngine.php @@ -0,0 +1,30 @@ +loadTextData($ref); + + $content = PhabricatorSyntaxHighlighter::highlightWithFilename( + $ref->getName(), + $content); + + return $this->newTextDocumentContent($content); + } + +} diff --git a/src/applications/files/document/PhabricatorTextDocumentEngine.php b/src/applications/files/document/PhabricatorTextDocumentEngine.php new file mode 100644 index 0000000000..506c73badb --- /dev/null +++ b/src/applications/files/document/PhabricatorTextDocumentEngine.php @@ -0,0 +1,33 @@ +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; + } + +} diff --git a/webroot/rsrc/css/layout/phabricator-source-code-view.css b/webroot/rsrc/css/layout/phabricator-source-code-view.css index 446366cdf1..1836d321a5 100644 --- a/webroot/rsrc/css/layout/phabricator-source-code-view.css +++ b/webroot/rsrc/css/layout/phabricator-source-code-view.css @@ -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; } diff --git a/webroot/rsrc/css/phui/phui-property-list-view.css b/webroot/rsrc/css/phui/phui-property-list-view.css index 0ff882a746..c1f9944cbd 100644 --- a/webroot/rsrc/css/phui/phui-property-list-view.css +++ b/webroot/rsrc/css/phui/phui-property-list-view.css @@ -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;