コード例 #1
0
ファイル: Generator.php プロジェクト: poef/ariadne
 /**
  * Generates the CSS
  *
  * @param ILess_Environment $env
  * @return string
  */
 public function generateCSS(ILess_Environment $env)
 {
     $output = new ILess_Output_Mapped($this->contentsMap, $this);
     // catch the output
     $this->root->generateCSS($env, $output);
     // prepare sources
     foreach ($this->contentsMap as $filename => $contents) {
         // match md5 hash in square brackets _[#HASH#]_
         // see ILess_Parser_Core::parseString()
         if (preg_match('/(\\[__[0-9a-f]{32}__\\])+$/', $filename)) {
             $filename = substr($filename, 0, -38);
         }
         $this->sources[$this->normalizeFilename($filename)] = $contents;
     }
     $sourceMapUrl = null;
     if ($url = $this->getOption('url')) {
         $sourceMapUrl = $url;
     } elseif ($path = $this->getOption('filename')) {
         $sourceMapUrl = $this->normalizeFilename($path);
         // naming conventions, make it foobar.css.map
         if (!preg_match('/\\.map$/', $sourceMapUrl)) {
             $sourceMapUrl = sprintf('%s.map', $sourceMapUrl);
         }
     }
     $sourceMapContent = $this->generateJson();
     // write map to a file
     if ($file = $this->getOption('write_to')) {
         // FIXME: should this happen here?
         $this->saveMap($file, $sourceMapContent);
     } else {
         $sourceMapUrl = sprintf('data:application/json,%s', ILess_Util::encodeURIComponent($sourceMapContent));
     }
     if ($sourceMapUrl) {
         $output->add(sprintf('/*# sourceMappingURL=%s */', $sourceMapUrl));
     }
     return $output->toString();
 }