/** * @param string $in Filename without path or extension. * @return bool True if the output file was saved. */ public function compileFile($in) { $gantry = Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; $out = $this->getCssUrl($in); $path = $locator->findResource($out, true, true); $paths = $locator->mergeResources($this->paths); // Set the lookup paths. $this->compiler->setBasePath($path); $this->compiler->setImportDir($paths); $this->compiler->setFormatter('lessjs'); // Run the compiler. $this->compiler->setVariables($this->getVariables()); $css = $this->compiler->compileFile($in . '.less"'); $file = File::instance($path); // 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(); $this->createMeta($out, md5($css)); return true; }
/** * @param string $in Filename without path or extension. * @return bool True if the output file was saved. */ public function compileFile($in) { // Buy some extra time as compilation may take a lot of time in shared environments. @set_time_limit(30); $gantry = Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; $out = $this->getCssUrl($in); $path = $locator->findResource($out, true, true); $paths = $locator->mergeResources($this->paths); // Set the lookup paths. $this->compiler->setBasePath($path); $this->compiler->setImportDir($paths); // Run the compiler. $this->compiler->setVariables($this->getVariables()); $css = $this->compiler->compileFile($in . '.less"'); if (!$this->production) { $warning = <<<WARN /* GANTRY5 DEVELOPMENT MODE ENABLED. WARNING: This file is automatically generated by Gantry5. Any modifications to this file will be lost! For more information on modifying CSS, please read: http://docs.gantry.org/gantry5/configure/styles http://docs.gantry.org/gantry5/tutorials/adding-a-custom-style-sheet */ WARN; $css = $warning . "\n\n" . $css; } $file = File::instance($path); // Attempt to lock the file for writing. try { $file->lock(false); } catch (\Exception $e) { // Another process has locked the file; we will check this in a bit. } //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(); $this->createMeta($out, md5($css)); return true; }