public function SassScriptParser::interpolate in Sassy 7.3
Same name and namespace in other branches
- 7 phamlp/sass/script/SassScriptParser.php \SassScriptParser::interpolate()
Replace interpolated SassScript contained in '#{}' with the parsed value.
Parameters
string the text to interpolate:
SassContext the context in which the string is interpolated:
Return value
string the interpolated text
1 call to SassScriptParser::interpolate()
- SassScriptParser::evaluate in phpsass/
script/ SassScriptParser.php - Evaluate a SassScript.
File
- phpsass/
script/ SassScriptParser.php, line 58
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 …
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);
}