You are here

public static function SassExtentionsCompassFunctionsColourStops::colour_stops in Sassy 7

File

phamlp/sass/extensions/compass/functions/colourStops.php, line 194

Class

SassExtentionsCompassFunctionsColourStops
Compass extension SassScript colour stops functions class. A collection of functions for use in SassSCript. @package PHamlP @subpackage Sass.extensions.compass.functions

Code

public static function colour_stops() {
  $args = func_get_args();
  $list = array();
  foreach ($args as $arg) {
    if ($arg instanceof SassColour) {
      $list[] = new CompassColourStop($arg);
    }
    elseif ($arg instanceof SassString) {

      # We get a string as the result of concatenation

      # So we have to reparse the expression
      $colour = $stop = null;
      if (empty($parser)) {
        $parser = new SassScriptParser();
      }
      $expr = $parser
        ->parse($arg->value, SassScriptParser::$context);
      $x = array_pop($expr);
      if ($x instanceof SassColour) {
        $colour = $x;
      }
      elseif ($x instanceof SassScriptOperation) {
        if ($x->operator != 'concat') {

          # This should never happen.
          throw new SassScriptFunctionException("Couldn't parse a colour stop from: {value}", array(
            '{value}' => $arg->value,
          ), SassScriptParser::$context->node);
        }
        $colour = $expr[0];
        $stop = $expr[1];
      }
      else {
        throw new SassScriptFunctionException("Couldn't parse a colour stop from: {value}", array(
          '{value}' => $arg->value,
        ), SassScriptParser::$context->node);
      }
      $list[] = new CompassColourStop($colour, $stop);
    }
    else {
      throw new SassScriptFunctionException('Not a valid color stop: {arg}', array(
        '{arg}' => $arg->value,
      ), SassScriptParser::$context->node);
    }
  }
  return new CompassList($list);
}