mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 05:50:55 +01:00
Make celerity be able to render full uris
Summary: ...and use 'em in the phame blog case. Test Plan: viewed blog.phabricator.dev and it actually looked right! Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T1373 Differential Revision: https://secure.phabricator.com/D3666
This commit is contained in:
parent
9adfd11ed7
commit
ce1a585166
2 changed files with 29 additions and 6 deletions
|
@ -160,8 +160,8 @@ abstract class AphrontApplicationConfiguration {
|
|||
$path = '/phame/posts/'.trim($path, '/').'/';
|
||||
}
|
||||
|
||||
// TODO - now we need to tell Celerity to render static resources with
|
||||
// full URIs like secure.phabricator.org/rsrc/blahblah
|
||||
$celerity = CelerityAPI::getStaticResourceResponse();
|
||||
$celerity->setUseFullURI(true);
|
||||
}
|
||||
|
||||
list($controller, $uri_data) = $this->buildControllerForPath($path);
|
||||
|
|
|
@ -33,6 +33,7 @@ final class CelerityStaticResourceResponse {
|
|||
private $metadataBlock = 0;
|
||||
private $behaviors = array();
|
||||
private $hasRendered = array();
|
||||
private $useFullURI = false;
|
||||
|
||||
public function __construct() {
|
||||
if (isset($_REQUEST['__metablock__'])) {
|
||||
|
@ -85,6 +86,19 @@ final class CelerityStaticResourceResponse {
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* If set to true, Celerity will print full URIs (including the domain)
|
||||
* for static resources.
|
||||
*/
|
||||
public function setUseFullURI($should) {
|
||||
$this->useFullURI = $should;
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function shouldUseFullURI() {
|
||||
return $this->useFullURI;
|
||||
}
|
||||
|
||||
public function renderSingleResource($symbol) {
|
||||
$map = CelerityResourceMap::getInstance();
|
||||
$resolved = $map->resolveResources(array($symbol));
|
||||
|
@ -119,18 +133,27 @@ final class CelerityStaticResourceResponse {
|
|||
}
|
||||
|
||||
private function renderResource(array $resource) {
|
||||
$uri = $this->getURI($resource['uri']);
|
||||
switch ($resource['type']) {
|
||||
case 'css':
|
||||
$path = phutil_escape_html($resource['uri']);
|
||||
return '<link rel="stylesheet" type="text/css" href="'.$path.'" />';
|
||||
return '<link rel="stylesheet" type="text/css" href="'.$uri.'" />';
|
||||
case 'js':
|
||||
$path = phutil_escape_html($resource['uri']);
|
||||
return '<script type="text/javascript" src="'.$path.'">'.
|
||||
return '<script type="text/javascript" src="'.$uri.'">'.
|
||||
'</script>';
|
||||
}
|
||||
throw new Exception("Unable to render resource.");
|
||||
}
|
||||
|
||||
private function getURI($path) {
|
||||
$path = phutil_escape_html($path);
|
||||
if ($this->shouldUseFullURI()) {
|
||||
$uri = PhabricatorEnv::getCDNURI($path);
|
||||
} else {
|
||||
$uri = $path;
|
||||
}
|
||||
return $uri;
|
||||
}
|
||||
|
||||
public function renderHTMLFooter() {
|
||||
$data = array();
|
||||
if ($this->metadata) {
|
||||
|
|
Loading…
Reference in a new issue