From 9fa4c2d406cf5b68e3aef567a9c6f81d7dcc0b82 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 16 Oct 2012 10:33:47 -0700 Subject: [PATCH] Separate "PhabricatorBarePageView" out of "PhabricatorStandardPageView" Summary: For Phame, we really want more than a chromeless page -- it shouldn't have Javelin or Phabricator styles on it. Pull the bare infrastructure out of StandardPageView and make it available as BarePageView. Test Plan: Viewed bare page in UIExamples, various non-bare pages. Reviewers: btrahan Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D3711 --- src/__phutil_library_map__.php | 6 +- .../PhabricatorUIExampleRenderController.php | 4 +- .../examples/PhabricatorBarePageExample.php | 41 ++++++ src/view/page/AphrontPageView.php | 12 +- src/view/page/PhabricatorBarePageView.php | 121 ++++++++++++++++++ src/view/page/PhabricatorStandardPageView.php | 93 ++++---------- 6 files changed, 204 insertions(+), 73 deletions(-) create mode 100644 src/applications/uiexample/examples/PhabricatorBarePageExample.php create mode 100644 src/view/page/PhabricatorBarePageView.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index eac0000185..3e0e10f56d 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -601,6 +601,8 @@ phutil_register_library_map(array( 'PhabricatorAuditReplyHandler' => 'applications/audit/PhabricatorAuditReplyHandler.php', 'PhabricatorAuditStatusConstants' => 'applications/audit/constants/PhabricatorAuditStatusConstants.php', 'PhabricatorAuthController' => 'applications/auth/controller/PhabricatorAuthController.php', + 'PhabricatorBarePageExample' => 'applications/uiexample/examples/PhabricatorBarePageExample.php', + 'PhabricatorBarePageView' => 'view/page/PhabricatorBarePageView.php', 'PhabricatorBaseEnglishTranslation' => 'infrastructure/internationalization/PhabricatorBaseEnglishTranslation.php', 'PhabricatorBlogSkin' => 'applications/phame/view/skins/PhabricatorBlogSkin.php', 'PhabricatorBuiltinPatchList' => 'infrastructure/storage/patch/PhabricatorBuiltinPatchList.php', @@ -1785,6 +1787,8 @@ phutil_register_library_map(array( 'PhabricatorAuditPreviewController' => 'PhabricatorAuditController', 'PhabricatorAuditReplyHandler' => 'PhabricatorMailReplyHandler', 'PhabricatorAuthController' => 'PhabricatorController', + 'PhabricatorBarePageExample' => 'PhabricatorUIExample', + 'PhabricatorBarePageView' => 'AphrontPageView', 'PhabricatorBaseEnglishTranslation' => 'PhabricatorTranslation', 'PhabricatorBlogSkin' => 'PhameBlogSkin', 'PhabricatorBuiltinPatchList' => 'PhabricatorSQLPatchList', @@ -2203,7 +2207,7 @@ phutil_register_library_map(array( 'PhabricatorSlugTestCase' => 'PhabricatorTestCase', 'PhabricatorSortTableExample' => 'PhabricatorUIExample', 'PhabricatorSourceCodeView' => 'AphrontView', - 'PhabricatorStandardPageView' => 'AphrontPageView', + 'PhabricatorStandardPageView' => 'PhabricatorBarePageView', 'PhabricatorStatusController' => 'PhabricatorController', 'PhabricatorStorageManagementDatabasesWorkflow' => 'PhabricatorStorageManagementWorkflow', 'PhabricatorStorageManagementDestroyWorkflow' => 'PhabricatorStorageManagementWorkflow', diff --git a/src/applications/uiexample/controller/PhabricatorUIExampleRenderController.php b/src/applications/uiexample/controller/PhabricatorUIExampleRenderController.php index 947cc12328..556871358b 100644 --- a/src/applications/uiexample/controller/PhabricatorUIExampleRenderController.php +++ b/src/applications/uiexample/controller/PhabricatorUIExampleRenderController.php @@ -48,8 +48,6 @@ final class PhabricatorUIExampleRenderController extends PhabricatorController { $selected = $nav->selectFilter($this->class, head_key($classes)); - require_celerity_resource('phabricator-ui-example-css'); - $example = $classes[$selected]; $example->setRequest($this->getRequest()); @@ -59,6 +57,8 @@ final class PhabricatorUIExampleRenderController extends PhabricatorController { return $result; } + require_celerity_resource('phabricator-ui-example-css'); + $nav->appendChild( '
'. '

'. diff --git a/src/applications/uiexample/examples/PhabricatorBarePageExample.php b/src/applications/uiexample/examples/PhabricatorBarePageExample.php new file mode 100644 index 0000000000..598673bd0e --- /dev/null +++ b/src/applications/uiexample/examples/PhabricatorBarePageExample.php @@ -0,0 +1,41 @@ +appendChild( + phutil_render_tag( + 'h1', + array(), + phutil_escape_html($this->getDescription()))); + + $response = new AphrontWebpageResponse(); + $response->setContent($view->render()); + return $response; + } +} diff --git a/src/view/page/AphrontPageView.php b/src/view/page/AphrontPageView.php index a064cb29c7..6b36e50bcc 100644 --- a/src/view/page/AphrontPageView.php +++ b/src/view/page/AphrontPageView.php @@ -68,6 +68,13 @@ abstract class AphrontPageView extends AphrontView { $body_classes = $this->getBodyClasses(); + $body = phutil_render_tag( + 'body', + array( + 'class' => nonempty($body_classes, null), + ), + $body.$tail); + $response = << @@ -76,10 +83,7 @@ abstract class AphrontPageView extends AphrontView { {$title} {$head} - - {$body} - {$tail} - + {$body} EOHTML; diff --git a/src/view/page/PhabricatorBarePageView.php b/src/view/page/PhabricatorBarePageView.php new file mode 100644 index 0000000000..755ecd4388 --- /dev/null +++ b/src/view/page/PhabricatorBarePageView.php @@ -0,0 +1,121 @@ +controller = $controller; + return $this; + } + + public function getController() { + return $this->controller; + } + + public function setRequest(AphrontRequest $request) { + $this->request = $request; + return $this; + } + + public function getRequest() { + return $this->request; + } + + public function setFrameable($frameable) { + $this->frameable = $frameable; + return $this; + } + + public function getFrameable() { + return $this->frameable; + } + + public function setDeviceReady($device_ready) { + $this->deviceReady = $device_ready; + return $this; + } + + public function getDeviceReady() { + return $this->deviceReady; + } + + protected function willRenderPage() { + // We render this now to resolve static resources so they can appear in the + // document head. + $this->bodyContent = $this->renderChildren(); + } + + protected function getHead() { + $framebust = null; + if (!$this->getFrameable()) { + $framebust = '(top != self) && top.location.replace(self.location.href);'; + } + + $viewport_tag = null; + if (PhabricatorEnv::getEnvConfig('preview.viewport-meta-tag') || + $this->getDeviceReady()) { + $viewport_tag = phutil_render_tag( + 'meta', + array( + 'name' => 'viewport', + 'content' => 'width=device-width, '. + 'initial-scale=1, '. + 'maximum-scale=1', + )); + } + + $response = CelerityAPI::getStaticResourceResponse(); + + $head = array( + $viewport_tag, + + '', + + $response->renderResourcesOfType('css'), + ); + + return implode("\n", $head); + } + + protected function getBody() { + return $this->bodyContent; + } + + protected function getTail() { + $response = CelerityAPI::getStaticResourceResponse(); + return $response->renderResourcesOfType('js'); + } + +} diff --git a/src/view/page/PhabricatorStandardPageView.php b/src/view/page/PhabricatorStandardPageView.php index 8b10b287a8..fa0cad2e34 100644 --- a/src/view/page/PhabricatorStandardPageView.php +++ b/src/view/page/PhabricatorStandardPageView.php @@ -16,50 +16,27 @@ * limitations under the License. */ -final class PhabricatorStandardPageView extends AphrontPageView { +/** + * This is a standard Phabricator page with menus, Javelin, DarkConsole, and + * basic styles. + * + */ +final class PhabricatorStandardPageView extends PhabricatorBarePageView { private $baseURI; private $applicationName; private $glyph; - private $bodyContent; private $menuContent; - private $request; private $showChrome = true; - private $isFrameable = false; private $disableConsole; private $searchDefaultScope; private $pageObjects = array(); - private $controller; - - - public function setController(AphrontController $controller) { - $this->controller = $controller; - return $this; - } - - public function getController() { - return $this->controller; - } - - public function setRequest($request) { - $this->request = $request; - return $this; - } - - public function getRequest() { - return $this->request; - } public function setApplicationName($application_name) { $this->applicationName = $application_name; return $this; } - public function setFrameable($frameable) { - $this->isFrameable = $frameable; - return $this; - } - public function setDisableConsole($disable) { $this->disableConsole = $disable; return $this; @@ -120,6 +97,7 @@ final class PhabricatorStandardPageView extends AphrontPageView { protected function willRenderPage() { + parent::willRenderPage(); if (!$this->getRequest()) { throw new Exception( @@ -168,19 +146,10 @@ final class PhabricatorStandardPageView extends AphrontPageView { } $this->menuContent = $this->renderMainMenu(); - $this->bodyContent = $this->renderChildren(); } protected function getHead() { - - $framebust = null; - if (!$this->isFrameable) { - $framebust = '(top != self) && top.location.replace(self.location.href);'; - } - - $response = CelerityAPI::getStaticResourceResponse(); - $monospaced = PhabricatorEnv::getEnvConfig('style.monospace'); $request = $this->getRequest(); @@ -194,32 +163,17 @@ final class PhabricatorStandardPageView extends AphrontPageView { } } - $viewport_tag = null; - if (PhabricatorEnv::getEnvConfig('preview.viewport-meta-tag') || - $this->deviceReady) { - $viewport_tag = phutil_render_tag( - 'meta', - array( - 'name' => 'viewport', - 'content' => 'width=device-width, '. - 'initial-scale=1, '. - 'maximum-scale=1', - )); - } + $response = CelerityAPI::getStaticResourceResponse(); - $head = - $viewport_tag. - ''. - $response->renderResourcesOfType('css'). + $head = array( + parent::getHead(), ''. - $response->renderSingleResource('javelin-magical-init'); + '', + $response->renderSingleResource('javelin-magical-init'), + ); - return $head; + return implode("\n", $head); } public function setGlyph($glyph) { @@ -232,6 +186,8 @@ final class PhabricatorStandardPageView extends AphrontPageView { } protected function willSendResponse($response) { + $response = parent::willSendResponse($response); + $console = $this->getRequest()->getApplicationConfiguration()->getConsole(); if ($console) { $response = str_replace( @@ -239,6 +195,7 @@ final class PhabricatorStandardPageView extends AphrontPageView { $console->render($this->getRequest()), $response); } + return $response; } @@ -293,7 +250,7 @@ final class PhabricatorStandardPageView extends AphrontPageView { if ($this->getShowChrome()) { $header_chrome = $this->menuContent; - if (!$this->deviceReady) { + if (!$this->getDeviceReady()) { $footer_chrome = $this->renderFooter(); } } @@ -336,7 +293,7 @@ final class PhabricatorStandardPageView extends AphrontPageView { '
'. ($console ? '' : null). $developer_warning. - $this->bodyContent. + parent::getBody(). '
'. '
'). $footer_chrome; @@ -382,10 +339,14 @@ final class PhabricatorStandardPageView extends AphrontPageView { } $response = CelerityAPI::getStaticResourceResponse(); - return - $response->renderResourcesOfType('js'). - $container. - $response->renderHTMLFooter(); + + $tail = array( + parent::getTail(), + $container, + $response->renderHTMLFooter(), + ); + + return implode("\n", $tail); } protected function getBodyClasses() {