/** * Transforms CSS into XML * * @return string $css */ public static function to_xml($css) { # Convert comments self::$comments = array(); $xml = preg_replace_callback('/\\/\\*(.*?)\\*\\//sx', array('NestedSelectors', 'encode_comment'), $css); # Convert imports $xml = preg_replace('/ @import\\s+ (?:url\\(\\s*)? # maybe url( [\'"]? # maybe quote (.*?) # 1 = URI [\'"]? # maybe end quote (?:\\s*\\))? # maybe ) ([a-zA-Z,\\s]*)? # 2 = media list ; # end token /x', "<import url=\"\$1\" media=\"\$2\" />", $xml); # Add semi-colons to the ends of property lists which don't have them $xml = preg_replace('/((\\:|\\+)[^;])*?\\}/', "\$1;}", $xml); # Transform properties $xml = preg_replace('/([-_A-Za-z*]+)\\s*:\\s*([^;}{]+)(?:;)/ie', "'<property name=\"'.trim('\$1').'\" value=\"'.trim('\$2').'\" />\n'", $xml); # Transform selectors $xml = preg_replace('/(\\s*)([_@#.0-9A-Za-z\\/\\+~*\\|\\(\\)\\[\\]^\\"\'=\\$:,\\s-]*?)\\{/me', "'\$1\n<rule selector=\"'.preg_replace('/\\s+/', ' ', trim('\$2')).'\">\n'", $xml); # Close rules $xml = preg_replace('/\\;?\\s*\\}/', "\n</rule>", $xml); # Indent everything one tab $xml = preg_replace('/\\n/', "\r\t", $xml); # Tie it up with a bow $xml = '<?xml version="1.0" ?' . ">\r<css>\r\t{$xml}\r</css>\r"; return simplexml_load_string($xml); }
/** * 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')); } } } }