コード例 #1
0
 public function generate()
 {
     foreach ($this->files as $file) {
         mark('解析CSS文件:' . $file);
         $this->file = $file;
         $content = file_get_contents($file);
         $cssDoc = JCssParser::parse($content);
         foreach ($cssDoc['stylesheet']['rules'] as $rule) {
             if ($rule['type'] === 'rule') {
                 $bgDecls = array();
                 $merge = null;
                 foreach ($rule['declarations'] as $declaration) {
                     if (strpos($declaration['property'], 'background') !== false) {
                         array_push($bgDecls, $declaration);
                     } elseif ($declaration['property'] === 'merge') {
                         $merge = $declaration['value'];
                     }
                 }
                 if ($merge) {
                     $this->setConfigByRule($merge, $bgDecls);
                 }
             }
         }
     }
     return $this;
 }
コード例 #2
0
 /**
  * css解析入口
  * @param $contents {String} css文本内容
  * @return string {String} 处理后的文件
  */
 protected function cssParse($contents)
 {
     // 处理逻辑
     $doc = JCssParser::parse($contents);
     $ret = new stdClass();
     $ret->return = null;
     trigger('css_parse_start', $this, $doc, $ret);
     if ($ret->return) {
         $doc = $ret->return;
     }
     $importContents = $this->handleImport($doc['stylesheet']['rules']);
     if ($this->isReplaceUri) {
         $this->handleBackground($doc['stylesheet']['rules']);
     }
     return $importContents . JCssParser::stringify($doc);
 }
コード例 #3
0
ファイル: JCssParser.php プロジェクト: chenyongze/m3d
 private static function comment()
 {
     if (self::$css[0] !== '/' || self::$css[1] !== '*') {
         return null;
     }
     $i = 2;
     while (isset(self::$css[$i]) && (self::$css[$i] !== '*' || isset(self::$css[$i + 1]) && self::$css[$i + 1] !== '/')) {
         ++$i;
     }
     $i += 2;
     if (!isset(self::$css[$i - 1])) {
         throw new Exception('End of comment missing');
     }
     $str = substr(self::$css, 2, $i - 2 - 2);
     self::$css = substr(self::$css, $i);
     self::whitespace();
     return array('type' => 'comment', 'comment' => $str);
 }