Source of file SassWhileNode.php
Size: 1,728 Bytes - Last Modified: 2021-12-23T10:32:55+00:00
/var/www/docs.ssmods.com/process/src/code/phpsass/tree/SassWhileNode.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 | <?php /* SVN FILE: $Id$ */ /** * SassWhileNode class file. * @author Chris Yates <chris.l.yates@gmail.com> * @copyright Copyright (c) 2010 PBM Web Development * @license http://phamlp.googlecode.com/files/license.txt * @package PHamlP * @subpackage Sass.tree */ /** * SassWhileNode class. * Represents a Sass @while loop and a Sass @do loop. * @package PHamlP * @subpackage Sass.tree */ class SassWhileNode extends SassNode { const MATCH = '/^@(do|while)\s+(.+)$/i'; const LOOP = 1; const EXPRESSION = 2; const IS_DO = 'do'; /** * @var boolean whether this is a do/while. * A do/while loop is guarenteed to run at least once. */ private $isDo; /** * @var string expression to evaluate */ private $expression; /** * SassWhileNode constructor. * @param object source token * @return SassWhileNode */ public function __construct($token) { parent::__construct($token); preg_match(self::MATCH, $token->source, $matches); $this->expression = $matches[self::EXPRESSION]; $this->isDo = ($matches[self::LOOP] === SassWhileNode::IS_DO); } /** * Parse this node. * @param SassContext the context in which this node is parsed * @return array the parsed child nodes */ public function parse($context) { $children = array(); if ($this->isDo) { do { $children = array_merge($children, $this->parseChildren($context)); } while ($this->evaluate($this->expression, $context)->toBoolean()); } else { while ($this->evaluate($this->expression, $context)->toBoolean()) { $children = array_merge($children, $this->parseChildren($context)); } } return $children; } } |