addImportPath() public method

Add import path
public addImportPath ( string $path )
$path string
示例#1
0
文件: Scss.php 项目: etu/0bRSS
 public function get($cssFile)
 {
     $scssPath = PROJECT_ROOT . '/src/scss';
     $scssFile = $scssPath . '/' . str_replace('css', 'scss', $cssFile);
     /** Pass the route if file don't exists, will result in 404 */
     if (!file_exists($scssFile)) {
         return $this->slim->pass();
     }
     $this->slim->response->headers->set('Content-Type', 'text/css');
     $this->compiler->addImportPath($scssPath);
     echo $this->compiler->compile(file_get_contents($scssFile));
 }
示例#2
0
 /**
  * Filters an asset just before it's dumped.
  *
  * @param AssetInterface $asset
  */
 public function filterDump(AssetInterface $asset)
 {
     $this->dispatch(new LoadThemeVariables($variables = new Collection()));
     $compiler = new Compiler();
     if ($dir = $asset->getSourceDirectory()) {
         $compiler->addImportPath($dir);
     }
     $compiler->setVariables($variables->all());
     $asset->setContent($this->parser->parse($compiler->compile($asset->getContent())));
 }
 /**
  * @param FileContainer $file
  *
  * @return $this
  * @throws CompilerException
  */
 protected function compileSCSS(FileContainer $file)
 {
     try {
         $this->scss->addImportPath(dirname($file->getInputPath()));
         $content = $this->scss->compile($file->getInputContent());
         return $file->setOutputContent($content);
     } catch (ParserException $e) {
         throw new CompilerException($e->getMessage(), 1, $e);
     }
 }
示例#4
0
 /**
  * Compile .scss file
  *
  * @param string $in  Input file (.scss)
  * @param string $out Output file (.css) optional
  *
  * @return string|bool
  */
 public function compileFile($in, $out = null)
 {
     if (!is_readable($in)) {
         throw new \Exception('load error: failed to find ' . $in);
     }
     $pi = pathinfo($in);
     $this->scss->addImportPath($pi['dirname'] . '/');
     $compiled = $this->scss->compile(file_get_contents($in), $in);
     if ($out !== null) {
         return file_put_contents($out, $compiled);
     }
     return $compiled;
 }
示例#5
0
 /**
  * @param array $sourceFiles
  * @param string $outputFile
  * @return array
  */
 protected function compile($sourceFiles, $outputFile)
 {
     $parsedFiles = [];
     $file = fopen($outputFile, 'w');
     foreach ($sourceFiles as $sourceFile) {
         $compiler = new Compiler();
         $compiler->addImportPath(dirname($sourceFile));
         fwrite($file, $compiler->compile(file_get_contents($sourceFile), $sourceFile) . "\n");
         fflush($file);
         $parsedFiles = array_merge($parsedFiles, $compiler->getParsedFiles());
     }
     fclose($file);
     return $parsedFiles;
 }
示例#6
0
 public static function compileFile(string $file, array $paths, string $formatter, bool $lineComments) : array
 {
     $location = static::resolveFile($file, $paths);
     $compiler = new Compiler();
     $compiler->setImportPaths(\dirname($location));
     $compiler->addImportPath(function (string $path) use($paths) {
         return static::resolveFile($path, $paths);
     });
     $compiler->setFormatter($formatter);
     if ($lineComments) {
         $compiler->setLineNumberStyle(Compiler::LINE_COMMENTS);
     }
     $css = $compiler->compile(\file_get_contents($location), $location);
     return [$css, $compiler->getParsedFiles()];
 }
示例#7
0
 public function compile()
 {
     // go on even if user "stops" the script by closing the browser, closing the terminal etc.
     ignore_user_abort(true);
     // set script running time to unlimited
     set_time_limit(0);
     $root_dir = $this->root_dir;
     $scss_compiler = new Compiler();
     $scss_compiler->setNumberPrecision(10);
     $scss_compiler->stripComments = $this->strip_comments;
     $scss_compiler->addImportPath(function ($path) use($root_dir) {
         $path = $root_dir . $path . '.scss';
         $path_parts = pathinfo($path);
         $underscore_file = $path_parts['dirname'] . '/_' . $path_parts['basename'];
         if (file_exists($underscore_file)) {
             $path = $underscore_file;
         }
         if (!file_exists($path)) {
             return null;
         }
         return $path;
     });
     // set the path to your to-be-imported mixins. please note: custom paths are coming up on future releases!
     //$scss_compiler->setImportPaths($scss_folder);
     // set css formatting (normal, nested or minimized), @see http://leafo.net/scssphp/docs/#output_formatting
     $scss_compiler->setFormatter($this->formatter);
     // get .scss's content, put it into $string_sass
     $string_sass = '';
     if (is_array($this->scss_file)) {
         foreach ($this->scss_file as $scss_file) {
             $string_sass .= file_get_contents($scss_file);
         }
     } else {
         $string_sass = file_get_contents($this->scss_file);
     }
     // try/catch block to prevent script stopping when scss compiler throws an error
     try {
         // compile this SASS code to CSS
         $string_css = $scss_compiler->compile($string_sass) . "\n";
         // $string_css = csscrush_string($string_css, $options = array('minify' => true));
         // write CSS into file with the same filename, but .css extension
         file_put_contents($this->css_file, $string_css);
     } catch (Exception $e) {
         // here we could put the exception message, but who cares ...
         echo $e->getMessage();
         exit;
     }
 }
示例#8
0
 public function getChildren(AssetFactory $factory, $content, $loadPath = null)
 {
     $sc = new Compiler();
     $sc->addImportPath($loadPath);
     foreach ($this->importPaths as $path) {
         $sc->addImportPath($path);
     }
     $children = array();
     foreach (CssUtils::extractImports($content) as $match) {
         $file = $sc->findImport($match);
         if ($file) {
             $children[] = $child = $factory->createAsset($file, array(), array('root' => $loadPath));
             $child->load();
             $children = array_merge($children, $this->getChildren($factory, $child->getContent(), $loadPath));
         }
     }
     return $children;
 }
示例#9
0
文件: Css.php 项目: is00hcw/munee
 /**
  * Callback method called before filters are run
  *
  * Overriding to run the file through LESS/SCSS if need be.
  * Also want to fix any relative paths for images.
  *
  * @param string $originalFile
  * @param string $cacheFile
  *
  * @throws CompilationException
  */
 protected function beforeFilter($originalFile, $cacheFile)
 {
     if ($this->isLess($originalFile)) {
         $less = new lessc();
         try {
             $compiledLess = $less->cachedCompile($originalFile);
         } catch (\Exception $e) {
             throw new CompilationException('Error in LESS Compiler', 0, $e);
         }
         $compiledLess['compiled'] = $this->fixRelativePaths($compiledLess['compiled'], $originalFile);
         file_put_contents($cacheFile, serialize($compiledLess));
     } elseif ($this->isScss($originalFile)) {
         $scss = new ScssCompiler();
         $scss->addImportPath(pathinfo($originalFile, PATHINFO_DIRNAME));
         try {
             $compiled = $scss->compile(file_get_contents($originalFile));
         } catch (\Exception $e) {
             throw new CompilationException('Error in SCSS Compiler', 0, $e);
         }
         $content = compact('compiled');
         $parsedFiles = $scss->getParsedFiles();
         $parsedFiles[] = $originalFile;
         foreach ($parsedFiles as $file) {
             $content['files'][$file] = filemtime($file);
         }
         $content['compiled'] = $this->fixRelativePaths($content['compiled'], $originalFile);
         file_put_contents($cacheFile, serialize($content));
     } else {
         $content = file_get_contents($originalFile);
         file_put_contents($cacheFile, $this->fixRelativePaths($content, $originalFile));
     }
 }