function test_Constants() { $this->dir('Constants'); $original = file_get_contents($this->dir() . 'in.css'); $expected = file_get_contents($this->dir() . 'out.css'); $css = Constants::pre_process($original); $css = Constants::replace($css); $this->assertEqual($css, $expected); }
/** * Parses @fors within the css * * @author Anthony Short * @param $string * @return string */ public static function parse($css) { if ($found = self::find_fors($css)) { foreach ($found[0] as $key => $value) { $s = ""; $constant = $found[1][$key]; $from = Constants::replace($found[2][$key]); $to = Constants::replace($found[3][$key]); $content = $found[6][$key]; for ($i = $from; $i <= $to; $i++) { Constants::set($constant, $i); $s .= Constants::replace($content); } $css = str_replace($found[0][$key], $s, $css); } } return $css; }
/** * Parses the parameters of the base * * @author Anthony Short * @param $params * @return array */ public static function parse_params($mixin_name, $params, $function_args = array()) { $parsed = array(); # Make sure any commas inside ()'s, such as rgba(255,255,255,0.5) are encoded before exploding # so that it doesn't break the rule. if (preg_match_all('/\\([^)]*?,[^)]*?\\)/', $params, $matches)) { foreach ($matches as $key => $value) { $original = $value; $new = str_replace(',', '#COMMA#', $value); $params = str_replace($original, $new, $params); } } $mixin_params = $params != "" ? explode(',', $params) : array(); # Loop through each function arg and create the parsed params array foreach ($function_args as $key => $value) { $v = explode('=', $value); # Remove the $ so we can set it as a constants $v[0] = str_replace('$', '', $v[0]); # If the user didn't include one of the params, we'll check to see if a default is available if (count($mixin_params) == 0 || !isset($mixin_params[$key])) { # If there is a default value for the param if (strstr($value, '=')) { $parsed_value = Constants::replace(Scaffold_Utils::unquote(trim($v[1]))); $parsed[trim($v[0])] = (string) $parsed_value; } else { throw new Exception("Missing mixin parameter - " . $mixin_name); } } else { $value = (string) Scaffold_Utils::unquote(trim($mixin_params[$key])); $parsed[trim($v[0])] = str_replace('#COMMA#', ',', $value); } } return $parsed; }
/** * Parse the CSS * * @return string - The processes css file as a string * @author Anthony Short **/ public static function parse_css() { # If the cache is stale or doesn't exist if (self::config('core.cache.mod_time') <= self::config('core.request.mod_time')) { # Start the timer Benchmark::start("parse_css"); # Compress it before parsing CSS::compress(CSS::$css); # Import CSS files Import::parse(); if (self::config('core.auto_include_mixins') === true) { # Import the mixins in the plugin/module folders Mixins::import_mixins('framework/mixins'); } # Parse our css through the plugins foreach (self::$plugins as $plugin) { call_user_func(array($plugin, 'import_process')); } # Compress it before parsing CSS::compress(CSS::$css); # Parse the constants Constants::parse(); foreach (self::$plugins as $plugin) { call_user_func(array($plugin, 'pre_process')); } # Parse the @grid Layout::parse_grid(); # Replace the constants Constants::replace(); # Parse @for loops Iteration::parse(); foreach (self::$plugins as $plugin) { call_user_func(array($plugin, 'process')); } # Compress it before parsing CSS::compress(CSS::$css); # Parse the mixins Mixins::parse(); # Find missing constants Constants::replace(); # Compress it before parsing CSS::compress(CSS::$css); foreach (self::$plugins as $plugin) { call_user_func(array($plugin, 'post_process')); } # Parse the expressions Expression::parse(); # Parse the nested selectors NestedSelectors::parse(); # Convert all url()'s to absolute paths if required if (self::config('core.absolute_urls') === true) { CSS::convert_to_absolute_urls(); } # Replaces url()'s that start with ~ to lead to the CSS directory CSS::replace_css_urls(); # Add the extra string we've been storing CSS::$css .= CSS::$append; # If they want to minify it if (self::config('core.minify_css') === true) { Minify::compress(); } else { CSS::pretty(); } # Formatting hook foreach (self::$plugins as $plugin) { call_user_func(array($plugin, 'formatting_process')); } # Validate the CSS if (self::config('core.validate') === true) { Validate::check(); } # Stop the timer... Benchmark::stop("parse_css"); if (self::config('core.show_header') === TRUE) { CSS::$css = "/* Processed by CSScaffold on " . gmdate('r') . " in " . Benchmark::get("parse_css", "time") . " seconds */\n\n" . CSS::$css; } # Write the css file to the cache self::cache_write(CSS::$css); # Output process hook for plugins to display views. # Doesn't run in production mode. if (!IN_PRODUCTION) { foreach (array_merge(self::$plugins, self::$modules) as $plugin) { call_user_func(array($plugin, 'output')); } } } }