示例#1
0
文件: Variables.php 项目: jankal/mvc
 /**
  * Apply the plugin to Css object
  *
  * @param Stylecow\Css $css The css object
  * @param array $rootVariables Optional variables not defined in css code
  */
 public static function apply(Css $css, array $rootVariables = array())
 {
     foreach ($css->getChildren(array(':root', 'html', 'body')) as $child) {
         $rootVariables = self::getVariables($child, $rootVariables);
     }
     $css->executeRecursive(function ($code, &$contextVariables) {
         $contextVariables = Variables::getVariables($code, $contextVariables);
         foreach ($code->properties as $property) {
             $property->value = Variables::replaceVariables($property->value, $contextVariables);
         }
     }, $rootVariables);
 }
示例#2
0
文件: Rem.php 项目: rrmodi88/stylecow
 /**
  * Apply the plugin to Css object
  *
  * @param Stylecow\Css $css The css object
  * @param int $rem The default value for rem. This value can be overwritten for the font-face property in :root, html or body
  */
 public static function apply(Css $css, $rem = 16)
 {
     foreach ($css->getChildren(array(':root', 'html', 'body')) as $child) {
         foreach ($child->getProperties('font-size') as $property) {
             $rem = Rem::rootPixels($property->value);
         }
     }
     $css->executeRecursive(function ($code) use($rem) {
         foreach ($code->getProperties() as $property) {
             if (strpos($property->value, 'rem') === false) {
                 continue;
             }
             $value = preg_replace_callback('/([0-9\\.]+)rem/', function ($matches) use($rem) {
                 return Rem::toPixels($matches[1], $rem);
             }, $property->value);
             if ($property->value !== $value) {
                 $code->addProperty(new Property($property->name, $value), $property->getPositionInParent());
             }
         }
     });
 }
示例#3
0
文件: Grid.php 项目: jankal/mvc
 /**
  * Search and return the css variables in an array. Removes also the css property
  *
  * @param array $properties The piece of the parsed css code with the properties
  *
  * @return array The transformed code
  */
 public static function getGrid(Css $css)
 {
     $grid = array();
     $gridChild = $css->getChildren('$grid');
     if (isset($gridChild[0])) {
         $gridChild[0]->removeFromParent();
         foreach ($gridChild[0]->getProperties(array('width', 'columns', 'gutter')) as $property) {
             $grid[$property->name] = $property->value;
         }
     }
     return $grid;
 }