From 4b43667086ae4faecb56bf54e0f743e53e0687a1 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 15 Oct 2015 10:20:19 -0700 Subject: [PATCH] Introduce PHUIRemarkupView, a sane way to work with Remarkup Summary: Fixes T9273. Remarkup has reasonably good fundamentals but the API is a giant pain to work with. Provide a `PHUIRemarkupView` to make it easier. This object is way simpler to use by default. It's not currently as powerful, but we can expand the power level later by adding more setters. Eventually I'd expect to replace `PhabricatorRemarkupInterface` and `PhabricatorMarkupOneOff` with this, but no rush on those. I converted a few callsites as a sanity check that it works OK. Test Plan: - Viewed remarkup in Passphrase. - Viewed remarkup in Badges. - Viewed a Conduit method. Reviewers: chad Reviewed By: chad Maniphest Tasks: T9273 Differential Revision: https://secure.phabricator.com/D14289 --- src/__phutil_library_map__.php | 2 ++ .../PhabricatorBadgesViewController.php | 8 ++--- .../PhabricatorConduitConsoleController.php | 9 ++---- .../PassphraseCredentialViewController.php | 6 +--- .../markup/PhabricatorMarkupOneOff.php | 11 +------ .../markup/view/PHUIRemarkupView.php | 32 +++++++++++++++++++ 6 files changed, 40 insertions(+), 28 deletions(-) create mode 100644 src/infrastructure/markup/view/PHUIRemarkupView.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 0c3995d41d..749876acc9 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1459,6 +1459,7 @@ phutil_register_library_map(array( 'PHUIPropertyListExample' => 'applications/uiexample/examples/PHUIPropertyListExample.php', 'PHUIPropertyListView' => 'view/phui/PHUIPropertyListView.php', 'PHUIRemarkupPreviewPanel' => 'view/phui/PHUIRemarkupPreviewPanel.php', + 'PHUIRemarkupView' => 'infrastructure/markup/view/PHUIRemarkupView.php', 'PHUISpacesNamespaceContextView' => 'applications/spaces/view/PHUISpacesNamespaceContextView.php', 'PHUIStatusItemView' => 'view/phui/PHUIStatusItemView.php', 'PHUIStatusListView' => 'view/phui/PHUIStatusListView.php', @@ -5352,6 +5353,7 @@ phutil_register_library_map(array( 'PHUIPropertyListExample' => 'PhabricatorUIExample', 'PHUIPropertyListView' => 'AphrontView', 'PHUIRemarkupPreviewPanel' => 'AphrontTagView', + 'PHUIRemarkupView' => 'AphrontView', 'PHUISpacesNamespaceContextView' => 'AphrontView', 'PHUIStatusItemView' => 'AphrontTagView', 'PHUIStatusListView' => 'AphrontTagView', diff --git a/src/applications/badges/controller/PhabricatorBadgesViewController.php b/src/applications/badges/controller/PhabricatorBadgesViewController.php index abaafe6d0f..411970f0bd 100644 --- a/src/applications/badges/controller/PhabricatorBadgesViewController.php +++ b/src/applications/badges/controller/PhabricatorBadgesViewController.php @@ -104,14 +104,10 @@ final class PhabricatorBadgesViewController $description = $badge->getDescription(); if (strlen($description)) { - $description = PhabricatorMarkupEngine::renderOneObject( - id(new PhabricatorMarkupOneOff())->setContent($description), - 'default', - $viewer); - $view->addSectionHeader( pht('Description'), PHUIPropertyListView::ICON_SUMMARY); - $view->addTextContent($description); + $view->addTextContent( + new PHUIRemarkupView($viewer, $description)); } $badge = id(new PHUIBadgeView()) diff --git a/src/applications/conduit/controller/PhabricatorConduitConsoleController.php b/src/applications/conduit/controller/PhabricatorConduitConsoleController.php index 79312b5480..e570861f29 100644 --- a/src/applications/conduit/controller/PhabricatorConduitConsoleController.php +++ b/src/applications/conduit/controller/PhabricatorConduitConsoleController.php @@ -195,15 +195,10 @@ final class PhabricatorConduitConsoleController pht('Errors'), $error_description); - - $description = $method->getMethodDescription(); - $description = PhabricatorMarkupEngine::renderOneObject( - id(new PhabricatorMarkupOneOff())->setContent($description), - 'default', - $viewer); $view->addSectionHeader( pht('Description'), PHUIPropertyListView::ICON_SUMMARY); - $view->addTextContent($description); + $view->addTextContent( + new PHUIRemarkupView($viewer, $method->getMethodDescription())); return $view; } diff --git a/src/applications/passphrase/controller/PassphraseCredentialViewController.php b/src/applications/passphrase/controller/PassphraseCredentialViewController.php index 46fd0c4c7a..46ae06cdc7 100644 --- a/src/applications/passphrase/controller/PassphraseCredentialViewController.php +++ b/src/applications/passphrase/controller/PassphraseCredentialViewController.php @@ -201,11 +201,7 @@ final class PassphraseCredentialViewController extends PassphraseController { pht('Description'), PHUIPropertyListView::ICON_SUMMARY); $properties->addTextContent( - PhabricatorMarkupEngine::renderOneObject( - id(new PhabricatorMarkupOneOff()) - ->setContent($description), - 'default', - $viewer)); + new PHUIRemarkupView($viewer, $description)); } return $properties; diff --git a/src/infrastructure/markup/PhabricatorMarkupOneOff.php b/src/infrastructure/markup/PhabricatorMarkupOneOff.php index 7f1708745c..0bfba1722f 100644 --- a/src/infrastructure/markup/PhabricatorMarkupOneOff.php +++ b/src/infrastructure/markup/PhabricatorMarkupOneOff.php @@ -1,16 +1,7 @@ setContent($some_content), - * 'default', - * $viewer); - * - * This is less efficient than batching rendering, but appropriate for small - * amounts of one-off text in form instructions. + * DEPRECATED. Use @{class:PHUIRemarkupView}. */ final class PhabricatorMarkupOneOff extends Phobject diff --git a/src/infrastructure/markup/view/PHUIRemarkupView.php b/src/infrastructure/markup/view/PHUIRemarkupView.php new file mode 100644 index 0000000000..0272c9c3a9 --- /dev/null +++ b/src/infrastructure/markup/view/PHUIRemarkupView.php @@ -0,0 +1,32 @@ +appendChild($fancy_text); + * + */ +final class PHUIRemarkupView extends AphrontView { + + private $corpus; + + public function __construct(PhabricatorUser $viewer, $corpus) { + $this->setUser($viewer); + $this->corpus = $corpus; + } + + public function render() { + $viewer = $this->getUser(); + $corpus = $this->corpus; + + return PhabricatorMarkupEngine::renderOneObject( + id(new PhabricatorMarkupOneOff()) + ->setContent($corpus), + 'default', + $viewer); + } + +}