mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-20 11:41:08 +01:00
Have AphrontView implement PhutilSafeHTMLProducerInterface
Summary: Allows views to work like tags. Test Plan: Implemented a few completely arbitrary render() / singleView simplifications. I just picked some that were easy to test. I'll do a more thorough pass on this in a followup; these calls don't really hurt anything. Reviewers: chad, vrana Reviewed By: chad CC: aran Differential Revision: https://secure.phabricator.com/D5306
This commit is contained in:
parent
25738e78a1
commit
5e41ead7c7
6 changed files with 32 additions and 22 deletions
|
@ -1652,7 +1652,11 @@ phutil_register_library_map(array(
|
||||||
'AphrontTokenizerTemplateView' => 'AphrontView',
|
'AphrontTokenizerTemplateView' => 'AphrontView',
|
||||||
'AphrontTypeaheadTemplateView' => 'AphrontView',
|
'AphrontTypeaheadTemplateView' => 'AphrontView',
|
||||||
'AphrontUsageException' => 'AphrontException',
|
'AphrontUsageException' => 'AphrontException',
|
||||||
'AphrontView' => 'Phobject',
|
'AphrontView' =>
|
||||||
|
array(
|
||||||
|
0 => 'Phobject',
|
||||||
|
1 => 'PhutilSafeHTMLProducerInterface',
|
||||||
|
),
|
||||||
'AphrontWebpageResponse' => 'AphrontHTMLResponse',
|
'AphrontWebpageResponse' => 'AphrontHTMLResponse',
|
||||||
'AuditPeopleMenuEventListener' => 'PhutilEventListener',
|
'AuditPeopleMenuEventListener' => 'PhutilEventListener',
|
||||||
'CelerityPhabricatorResourceController' => 'CelerityResourceController',
|
'CelerityPhabricatorResourceController' => 'CelerityResourceController',
|
||||||
|
|
|
@ -54,7 +54,7 @@ final class PhabricatorCalendarBrowseController
|
||||||
$nav->appendChild(
|
$nav->appendChild(
|
||||||
array(
|
array(
|
||||||
$this->getNoticeView(),
|
$this->getNoticeView(),
|
||||||
hsprintf('<div style="padding: 20px;">%s</div>', $month_view->render()),
|
hsprintf('<div style="padding: 20px;">%s</div>', $month_view),
|
||||||
));
|
));
|
||||||
|
|
||||||
return $this->buildApplicationPage(
|
return $this->buildApplicationPage(
|
||||||
|
|
|
@ -55,11 +55,10 @@ final class DifferentialInlineCommentEditView extends AphrontView {
|
||||||
'method' => 'POST',
|
'method' => 'POST',
|
||||||
'sigil' => 'inline-edit-form',
|
'sigil' => 'inline-edit-form',
|
||||||
),
|
),
|
||||||
$this->renderSingleView(
|
|
||||||
array(
|
array(
|
||||||
$this->renderInputs(),
|
$this->renderInputs(),
|
||||||
$this->renderBody(),
|
$this->renderBody(),
|
||||||
)));
|
));
|
||||||
|
|
||||||
return hsprintf(
|
return hsprintf(
|
||||||
'<table>'.
|
'<table>'.
|
||||||
|
@ -130,12 +129,11 @@ final class DifferentialInlineCommentEditView extends AphrontView {
|
||||||
array(
|
array(
|
||||||
'class' => 'differential-inline-comment-edit-buttons',
|
'class' => 'differential-inline-comment-edit-buttons',
|
||||||
),
|
),
|
||||||
$this->renderSingleView(
|
|
||||||
array(
|
array(
|
||||||
$formatting,
|
$formatting,
|
||||||
$buttons,
|
$buttons,
|
||||||
phutil_tag('div', array('style' => 'clear: both'), ''),
|
phutil_tag('div', array('style' => 'clear: both'), ''),
|
||||||
)));
|
));
|
||||||
|
|
||||||
return javelin_tag(
|
return javelin_tag(
|
||||||
'div',
|
'div',
|
||||||
|
@ -148,12 +146,11 @@ final class DifferentialInlineCommentEditView extends AphrontView {
|
||||||
'length' => $this->length,
|
'length' => $this->length,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
$this->renderSingleView(
|
|
||||||
array(
|
array(
|
||||||
$title,
|
$title,
|
||||||
$body,
|
$body,
|
||||||
$edit,
|
$edit,
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ from XSS and render correctly. Broadly:
|
||||||
- Combine elements with arrays, not string concatenation.
|
- Combine elements with arrays, not string concatenation.
|
||||||
- @{class:AphrontView} subclasses should return a
|
- @{class:AphrontView} subclasses should return a
|
||||||
@{class@libphutil:PhutilSafeHTML} object from their `render()` method.
|
@{class@libphutil:PhutilSafeHTML} object from their `render()` method.
|
||||||
|
- @{class:AphrontView} subclasses act like tags when rendering.
|
||||||
- @{function:pht} has some special rules.
|
- @{function:pht} has some special rules.
|
||||||
- There are some other things that you should be aware of.
|
- There are some other things that you should be aware of.
|
||||||
- Do not use @{function:phutil_render_tag} or @{function:javelin_render_tag},
|
- Do not use @{function:phutil_render_tag} or @{function:javelin_render_tag},
|
||||||
|
@ -124,6 +125,10 @@ return `phutil_tag()` or `javelin_tag()`:
|
||||||
|
|
||||||
return phutil_tag('div', ...);
|
return phutil_tag('div', ...);
|
||||||
|
|
||||||
|
You can use an @{class:AphrontView} subclass like you would a tag:
|
||||||
|
|
||||||
|
phutil_tag('div', array(), $view);
|
||||||
|
|
||||||
= Internationalization: pht() =
|
= Internationalization: pht() =
|
||||||
|
|
||||||
The @{function:pht} function has some special rules. If any input to
|
The @{function:pht} function has some special rules. If any input to
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
abstract class AphrontView extends Phobject {
|
abstract class AphrontView extends Phobject
|
||||||
|
implements PhutilSafeHTMLProducerInterface {
|
||||||
|
|
||||||
protected $user;
|
protected $user;
|
||||||
protected $children = array();
|
protected $children = array();
|
||||||
|
@ -65,4 +66,8 @@ abstract class AphrontView extends Phobject {
|
||||||
|
|
||||||
abstract public function render();
|
abstract public function render();
|
||||||
|
|
||||||
|
public function producePhutilSafeHTML() {
|
||||||
|
return $this->render();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,8 +145,7 @@ final class PhabricatorPropertyListView extends AphrontView {
|
||||||
|
|
||||||
$shortcuts = null;
|
$shortcuts = null;
|
||||||
if ($this->hasKeyboardShortcuts) {
|
if ($this->hasKeyboardShortcuts) {
|
||||||
$shortcuts =
|
$shortcuts = new AphrontKeyboardShortcutsAvailableView();
|
||||||
id(new AphrontKeyboardShortcutsAvailableView())->render();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
|
|
Loading…
Reference in a new issue