From 56c2b4a24b09f59034d9823f0c011b34cfe5b29d Mon Sep 17 00:00:00 2001 From: Matthias Schmid Date: Mon, 2 Mar 2015 16:36:58 +0100 Subject: [PATCH 1/2] added extensions for functions --- src/Compiler.php | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/Compiler.php b/src/Compiler.php index 5d36efbe..90ede9fb 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -1168,7 +1168,11 @@ protected function reduce($value, $inExp = false) // user defined function? $func = $this->get(self::$namespaces['function'] . $name, false); - if ($func) { + if ($this->isScssExtension($func)) { + return $this->executeScssExtension($func, $argValues); + + } else if ($func) { + $this->pushEnv(); // set the args @@ -1209,6 +1213,41 @@ protected function reduce($value, $inExp = false) } } + private $extensions = array(); + + /** + * @param string $extKey + * @param $extension + */ + public function addExtension($extKey, $extension) + { + $this->extensions[$extKey] = $extension; + } + + /** + * @param stdClass $func + * @param $argValues + * @return mixed + */ + private function executeScssExtension($func, $argValues) + { +// $this->pushEnv(); +// if (isset($func->args)) { +// $this->applyArguments($func->args, $argValues); +// } + + $callable = $this->extensions[$func->name]; + +// $this->popEnv(); + + return $callable($argValues); + } + + private function isScssExtension($func) + { + return array_key_exists($func->name, $this->extensions); + } + public function normalizeValue($value) { $value = $this->coerceForExpression($this->reduce($value)); From 2c1331f7fb6299a11a6b365baf9f1ce681b21b4b Mon Sep 17 00:00:00 2001 From: Matthias Schmid Date: Mon, 2 Mar 2015 16:52:10 +0100 Subject: [PATCH 2/2] fixed isScssExtension() --- src/Compiler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler.php b/src/Compiler.php index 90ede9fb..8afe7c54 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -1245,7 +1245,7 @@ private function executeScssExtension($func, $argValues) private function isScssExtension($func) { - return array_key_exists($func->name, $this->extensions); + return (false !== $func) && array_key_exists($func->name, $this->extensions); } public function normalizeValue($value)