示例#1
0
 /**
  * Parses embed() functions within the CSS.
  * @access public
  * @param $source
  * @param $scaffold
  * @return string
  */
 public function process($source, $scaffold)
 {
     // We can only embed for file sources
     if ($source->type != 'file') {
         return;
     }
     foreach (Scaffold_Helper_CSS::find_functions('embed', $source->contents) as $found) {
         // Get the full path to the file relative to the source
         $path = $source->find($url);
         // The file doesn't exist
         if ($path === false) {
             continue;
         }
         $id = 'embeds/' . md5($path);
         $ext = pathinfo($path, PATHINFO_EXTENSION);
         $mod_time = filemtime($path);
         $mime = $this->_get_mime($ext);
         // If it's a file we can actually use
         if ($mime === false) {
             continue;
         }
         // Try and load it from the cache
         $data = $scaffold->cache->get($id);
         // If the cached version has expired
         if ($data === false or $mod_time > $data->last_modified) {
             $data = base64_encode(file_get_contents($path));
             $scaffold->cache->set($id, $data, $mod_time, false);
         } else {
             $data = $data->contents;
         }
         $string = "url(data:{$mime};base64,{$data})";
         $source->contents = str_replace($found['string'], $string, $source->contents);
     }
 }
示例#2
0
 /**
  * Extracts the mixin bases
  * @param $source
  * @return return type
  */
 public function process($source)
 {
     print_r($source->get());
     exit;
     # Finds any selectors starting with =mixin-name
     if ($found = Scaffold_Helper_CSS::find_selectors('\\@mixin\\s+([0-9a-zA-Z_]+) (\\((.*?)\\))?', $source->get(), false)) {
         # Just to make life a little easier
         $full_base = $found[0];
         $base_names = $found['name'];
         $base_args = $found['args'];
         $base_props = $found['properties'];
         # Puts the mixin bases into a more suitable array
         foreach ($base_names as $key => $value) {
             $bases[$value]['properties'] = $base_props[$key];
             # If there are mixin arguments, add them
             $bases[$value]['params'] = $base_args[$key] != "" ? explode(',', $base_args[$key]) : array();
         }
         # Store this away for debugging
         $this->mixins = $bases;
         # Remove all of the mixin bases
         $source->set(str_replace($full_base, '', $source->get()));
     }
     print_r($this->mixins);
     exit;
 }
示例#3
0
 /**
  * Removes the @constant rules from a CSS string
  * @access public
  * @param $css
  * @return string
  */
 public function remove_constant_rules($css)
 {
     $rules = Scaffold_Helper_CSS::find_atrule('constants', $css);
     foreach ($rules as $rule) {
         $css = str_replace($rule[0], '', $css);
     }
     return $css;
 }
示例#4
0
 /**
  * @access public
  * @param $source
  * @return string
  */
 public function pre_process($source, $scaffold)
 {
     // Go through each custom function
     foreach ($this->functions as $name => $function) {
         $obj = $function[0];
         $method = $function[1];
         // Find them in the CSS
         foreach (Scaffold_Helper_CSS::find_functions($name, $source->contents) as $found) {
             // Call the hook method for this function
             $result = call_user_func_array(array($obj, $method), $found['params']);
             // Replace it in the CSS
             $source->contents = str_replace($found['string'], $result, $source->contents);
         }
     }
 }
示例#5
0
 /**
  * @access public
  * @param $source
  * @return string
  */
 public function pre_process($source)
 {
     // Go through each custom function
     foreach ($this->properties as $name => $property) {
         $obj = $property[0];
         $method = $property[1];
         // Find them in the CSS
         foreach (Scaffold_Helper_CSS::find_properties($name, $source->contents) as $found) {
             // Call the hook method for this function
             $result = call_user_func_array(array($obj, $method), array($found['value']));
             // Replace it in the CSS
             $source->contents = str_replace($found['property'], $result, $source->contents);
         }
     }
 }
示例#6
0
 public function testRemove_properties()
 {
     $string = 'id{background:blue}#id2{color:blue}#id3{background-color:red}#id4{dbackground:blue}#id5{color:red;background:blue}';
     $expected = 'id{}#id2{color:blue}#id3{background-color:red}#id4{dbackground:blue}#id5{color:red;}';
     $output = Scaffold_Helper_CSS::remove_properties('background', $string);
     $this->assertEquals($expected, $output);
     //
     $string = 'id{background:blue}#id2{color:blue}#id3{background-color:red}#id4{dbackground:blue}#id5{color:red;background:blue}';
     $expected = 'id{background:blue}#id2{color:blue}#id3{}#id4{dbackground:blue}#id5{color:red;background:blue}';
     $output = Scaffold_Helper_CSS::remove_properties('background-color', $string);
     $this->assertEquals($expected, $output);
 }
示例#7
0
 /**
  * Imports css via @import statements
  * @param $rules mixed
  * @param $css string
  * @param $base Search for files relative to this file
  * @return string
  */
 public function replace_rules($rules, $css, $base)
 {
     $unique = array_unique($rules[1]);
     $include = str_replace("\\", "/", $unique[0]);
     # If they haven't supplied an extension, we'll assume its a css file
     if (pathinfo($include, PATHINFO_EXTENSION) == "") {
         $include .= '.css';
     }
     # The base is set, and it's relative
     if ($include[0] != DIRECTORY_SEPARATOR) {
         $path = dirname($base) . DIRECTORY_SEPARATOR . $include;
     } elseif ($include[0] == DIRECTORY_SEPARATOR) {
         $path = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . $include;
     }
     if (!is_file($path)) {
         // Error message
         $title = "Missing File";
         $message = "<code>{$include}</code> cannot be found or doesn't exist.<pre><code> " . $rules[0][0] . "</code></pre>";
         $line = Scaffold_Helper_CSS::line_number($rules[0][0], $css);
         // Throw the error
         throw new Scaffold_Extension_Exception($title, $message, $base, $line);
     }
     # It's already been loaded
     if ($this->is_loaded($path)) {
         $css = str_replace($matches[0][0], '', $css);
     }
     $this->loaded[] = $path;
     # Check the file for more imports
     $contents = file_get_contents($path);
     $contents = $this->find_and_replace($contents, $path);
     # Replace the rule
     $css = str_replace($rules[0][0], $contents, $css);
     return $css;
 }