mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-24 06:20:56 +01:00
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
This commit is contained in:
parent
034ff3c870
commit
4b43667086
6 changed files with 40 additions and 28 deletions
|
@ -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',
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,16 +1,7 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Concrete object for accessing the markup engine with arbitrary blobs of
|
||||
* text, like form instructions. Usage:
|
||||
*
|
||||
* $output = PhabricatorMarkupEngine::renderOneObject(
|
||||
* id(new PhabricatorMarkupOneOff())->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
|
||||
|
|
32
src/infrastructure/markup/view/PHUIRemarkupView.php
Normal file
32
src/infrastructure/markup/view/PHUIRemarkupView.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Simple API for rendering blocks of Remarkup.
|
||||
*
|
||||
* Example usage:
|
||||
*
|
||||
* $fancy_text = new PHUIRemarkupView($viewer, $raw_remarkup);
|
||||
* $view->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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue