1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-20 12:30: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:
epriestley 2015-10-15 10:20:19 -07:00
parent 034ff3c870
commit 4b43667086
6 changed files with 40 additions and 28 deletions

View file

@ -1459,6 +1459,7 @@ phutil_register_library_map(array(
'PHUIPropertyListExample' => 'applications/uiexample/examples/PHUIPropertyListExample.php', 'PHUIPropertyListExample' => 'applications/uiexample/examples/PHUIPropertyListExample.php',
'PHUIPropertyListView' => 'view/phui/PHUIPropertyListView.php', 'PHUIPropertyListView' => 'view/phui/PHUIPropertyListView.php',
'PHUIRemarkupPreviewPanel' => 'view/phui/PHUIRemarkupPreviewPanel.php', 'PHUIRemarkupPreviewPanel' => 'view/phui/PHUIRemarkupPreviewPanel.php',
'PHUIRemarkupView' => 'infrastructure/markup/view/PHUIRemarkupView.php',
'PHUISpacesNamespaceContextView' => 'applications/spaces/view/PHUISpacesNamespaceContextView.php', 'PHUISpacesNamespaceContextView' => 'applications/spaces/view/PHUISpacesNamespaceContextView.php',
'PHUIStatusItemView' => 'view/phui/PHUIStatusItemView.php', 'PHUIStatusItemView' => 'view/phui/PHUIStatusItemView.php',
'PHUIStatusListView' => 'view/phui/PHUIStatusListView.php', 'PHUIStatusListView' => 'view/phui/PHUIStatusListView.php',
@ -5352,6 +5353,7 @@ phutil_register_library_map(array(
'PHUIPropertyListExample' => 'PhabricatorUIExample', 'PHUIPropertyListExample' => 'PhabricatorUIExample',
'PHUIPropertyListView' => 'AphrontView', 'PHUIPropertyListView' => 'AphrontView',
'PHUIRemarkupPreviewPanel' => 'AphrontTagView', 'PHUIRemarkupPreviewPanel' => 'AphrontTagView',
'PHUIRemarkupView' => 'AphrontView',
'PHUISpacesNamespaceContextView' => 'AphrontView', 'PHUISpacesNamespaceContextView' => 'AphrontView',
'PHUIStatusItemView' => 'AphrontTagView', 'PHUIStatusItemView' => 'AphrontTagView',
'PHUIStatusListView' => 'AphrontTagView', 'PHUIStatusListView' => 'AphrontTagView',

View file

@ -104,14 +104,10 @@ final class PhabricatorBadgesViewController
$description = $badge->getDescription(); $description = $badge->getDescription();
if (strlen($description)) { if (strlen($description)) {
$description = PhabricatorMarkupEngine::renderOneObject(
id(new PhabricatorMarkupOneOff())->setContent($description),
'default',
$viewer);
$view->addSectionHeader( $view->addSectionHeader(
pht('Description'), PHUIPropertyListView::ICON_SUMMARY); pht('Description'), PHUIPropertyListView::ICON_SUMMARY);
$view->addTextContent($description); $view->addTextContent(
new PHUIRemarkupView($viewer, $description));
} }
$badge = id(new PHUIBadgeView()) $badge = id(new PHUIBadgeView())

View file

@ -195,15 +195,10 @@ final class PhabricatorConduitConsoleController
pht('Errors'), pht('Errors'),
$error_description); $error_description);
$description = $method->getMethodDescription();
$description = PhabricatorMarkupEngine::renderOneObject(
id(new PhabricatorMarkupOneOff())->setContent($description),
'default',
$viewer);
$view->addSectionHeader( $view->addSectionHeader(
pht('Description'), PHUIPropertyListView::ICON_SUMMARY); pht('Description'), PHUIPropertyListView::ICON_SUMMARY);
$view->addTextContent($description); $view->addTextContent(
new PHUIRemarkupView($viewer, $method->getMethodDescription()));
return $view; return $view;
} }

View file

@ -201,11 +201,7 @@ final class PassphraseCredentialViewController extends PassphraseController {
pht('Description'), pht('Description'),
PHUIPropertyListView::ICON_SUMMARY); PHUIPropertyListView::ICON_SUMMARY);
$properties->addTextContent( $properties->addTextContent(
PhabricatorMarkupEngine::renderOneObject( new PHUIRemarkupView($viewer, $description));
id(new PhabricatorMarkupOneOff())
->setContent($description),
'default',
$viewer));
} }
return $properties; return $properties;

View file

@ -1,16 +1,7 @@
<?php <?php
/** /**
* Concrete object for accessing the markup engine with arbitrary blobs of * DEPRECATED. Use @{class:PHUIRemarkupView}.
* 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.
*/ */
final class PhabricatorMarkupOneOff final class PhabricatorMarkupOneOff
extends Phobject extends Phobject

View 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);
}
}