Esempio n. 1
0
 /**
  * @param string $in    Filename without path or extension.
  * @param string $out   Full path to the file to be written.
  * @return bool         True if the output file was saved.
  */
 public function compileFile($in, $out = null)
 {
     $gantry = Gantry::instance();
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     if (!$out) {
         $out = $locator->findResource($this->getCssUrl($in), true, true);
     }
     $paths = $locator->mergeResources($this->paths);
     // Set the lookup paths.
     $this->compiler->setBasePath($out);
     $this->compiler->setImportPaths($paths);
     $this->compiler->setFormatter('scss_formatter_nested');
     // Run the compiler.
     $this->compiler->setVariables($this->getVariables());
     $scss = '@import "' . $in . '.scss"';
     $css = $this->compiler->compile($scss);
     if (strpos($css, $scss) === 0) {
         $css = '/* ' . $scss . ' */';
     }
     $file = File::instance($out);
     // Attempt to lock the file for writing.
     $file->lock(false);
     //TODO: Better way to handle double writing files at same time.
     if ($file->locked() === false) {
         // File was already locked by another process.
         return false;
     }
     $file->save($css);
     $file->unlock();
     return true;
 }
Esempio n. 2
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     parent::__construct();
     $this->compiler = new Compiler();
     if ($this->production) {
         $this->compiler->setFormatter('Leafo\\ScssPhp\\Formatter\\Crunched');
     } else {
         $this->compiler->setFormatter('Leafo\\ScssPhp\\Formatter\\Expanded');
         $this->compiler->setLineNumberStyle(Compiler::LINE_COMMENTS);
     }
 }