Provide basic CSS variable replacement

Summary: See inlines.

Test Plan: Loaded timeline UIExample.

Reviewers: chad

Reviewed By: chad

CC: aran

Differential Revision: https://secure.phabricator.com/D6238
This commit is contained in:
epriestley 2013-06-19 15:42:17 -07:00
parent 6b1f15ac54
commit 8c36c43ecc
2 changed files with 27 additions and 2 deletions

View file

@ -9,6 +9,7 @@ final class CelerityResourceTransformer {
private $rawResourceMap; private $rawResourceMap;
private $celerityMap; private $celerityMap;
private $translateURICallback; private $translateURICallback;
private $currentPath;
public function setTranslateURICallback($translate_uricallback) { public function setTranslateURICallback($translate_uricallback) {
$this->translateURICallback = $translate_uricallback; $this->translateURICallback = $translate_uricallback;
@ -38,6 +39,7 @@ final class CelerityResourceTransformer {
switch ($type) { switch ($type) {
case 'css': case 'css':
$data = $this->replaceCSSVariables($path, $data);
$data = preg_replace_callback( $data = preg_replace_callback(
'@url\s*\((\s*[\'"]?.*?)\)@s', '@url\s*\((\s*[\'"]?.*?)\)@s',
nonempty( nonempty(
@ -119,4 +121,27 @@ final class CelerityResourceTransformer {
return 'url('.$uri.')'; return 'url('.$uri.')';
} }
private function replaceCSSVariables($path, $data) {
$this->currentPath = $path;
return preg_replace_callback(
'/{\$([^}]+)}/',
array($this, 'replaceCSSVariable'),
$data);
}
public function replaceCSSVariable($matches) {
static $map = array(
'red' => '#c0392b',
);
$var_name = $matches[1];
if (empty($map[$var_name])) {
$path = $this->currentPath;
throw new Exception(
"CSS file '{$path}' has unknown variable '{$var_name}'.");
}
return $map[$var_name];
}
} }

View file

@ -160,7 +160,7 @@
} }
.phabricator-timeline-red .phabricator-timeline-border { .phabricator-timeline-red .phabricator-timeline-border {
border-color: #c0392b; border-color: {$red};
} }
.phabricator-timeline-orange .phabricator-timeline-border { .phabricator-timeline-orange .phabricator-timeline-border {
@ -200,7 +200,7 @@
} }
.phabricator-timeline-red .phabricator-timeline-icon-fill { .phabricator-timeline-red .phabricator-timeline-icon-fill {
background-color: #c0392b; background-color: {$red};
} }
.phabricator-timeline-orange .phabricator-timeline-icon-fill { .phabricator-timeline-orange .phabricator-timeline-icon-fill {