public function SassScriptParser::interpolate in Sassy 7
Same name and namespace in other branches
- 7.3 phpsass/script/SassScriptParser.php \SassScriptParser::interpolate()
* Replace interpolated SassScript contained in '#{}' with the parsed value. *
Parameters
string the text to interpolate: * @param SassContext the context in which the string is interpolated * @return string the interpolated text
1 call to SassScriptParser::interpolate()
- SassScriptParser::evaluate in phamlp/
sass/ script/ SassScriptParser.php - * Evaluate a SassScript. *
File
- phamlp/
sass/ script/ SassScriptParser.php, line 52
Class
- SassScriptParser
- SassScriptParser class. Parses SassScript. SassScript is lexed into {@link http://en.wikipedia.org/wiki/Reverse_Polish_notation Reverse Polish notation} by the SassScriptLexer and the calculated result returned. @package PHamlP @subpackage Sass.script
Code
public function interpolate($string, $context) {
for ($i = 0, $n = preg_match_all(self::MATCH_INTERPOLATION, $string, $matches); $i < $n; $i++) {
$var = $this
->evaluate($matches[1][$i], $context)
->toString();
if (preg_match('/^unquote\\((["\'])(.*)\\1\\)$/', $var, $match)) {
$val = $match[2];
}
else {
if ($var == '""') {
$val = "";
}
else {
if (preg_match('/^(["\'])(.*)\\1$/', $var, $match)) {
$val = $match[2];
}
else {
$val = $var;
}
}
}
$matches[1][$i] = $val;
}
return str_replace($matches[0], $matches[1], $string);
}