public function getContent($processingTimeStart = null)
 {
     global $IP, $wgEnableSASSSourceMaps;
     wfProfileIn(__METHOD__);
     $processingTimeStart = null;
     if ($this->mForceProfile) {
         $processingTimeStart = microtime(true);
     }
     $memc = F::App()->wg->Memc;
     $this->mContent = null;
     $content = null;
     $sassService = null;
     $hasErrors = false;
     try {
         $sassService = SassService::newFromFile("{$IP}/{$this->mOid}");
         $sassService->setSassVariables($this->mParams);
         $sassService->enableSourceMaps(!empty($wgEnableSASSSourceMaps));
         $sassService->setFilters(SassService::FILTER_IMPORT_CSS | SassService::FILTER_CDN_REWRITE | SassService::FILTER_BASE64 | SassService::FILTER_JANUS);
         $cacheId = __CLASS__ . "-minified-" . $sassService->getCacheKey();
         $content = $memc->get($cacheId);
     } catch (Exception $e) {
         $content = "/* {$e->getMessage()} */";
         $hasErrors = true;
     }
     if ($content) {
         $this->mContent = $content;
     } else {
         // todo: add extra logging of AM request in case of any error
         try {
             $this->mContent = $sassService->getCss(false);
         } catch (Exception $e) {
             $this->mContent = $this->makeComment($e->getMessage());
             $hasErrors = true;
         }
         // This is the final pass on contents which, among other things, performs minification
         parent::getContent($processingTimeStart);
         // Prevent cache poisoning if we are serving sass from preview server
         if (!empty($cacheId) && getHostPrefix() == null && !$this->mForceProfile && !$hasErrors) {
             $memc->set($cacheId, $this->mContent, WikiaResponse::CACHE_STANDARD);
         }
     }
     if ($hasErrors) {
         wfProfileOut(__METHOD__);
         throw new Exception($this->mContent);
     }
     wfProfileOut(__METHOD__);
     return $this->mContent;
 }
 protected function processData($input)
 {
     $result = array();
     if (isset($input['styles'])) {
         $styles = $input['styles'];
         try {
             $sassService = SassService::newFromString($input['styles'], 0, '');
             $sassService->setFilters(SassService::FILTER_IMPORT_CSS | SassService::FILTER_CDN_REWRITE | SassService::FILTER_BASE64 | SassService::FILTER_JANUS | SassService::FILTER_MINIFY);
             $styles = '/*SASS*/' . $sassService->getCss();
         } catch (Exception $e) {
             $styles = "/* SASS processing failed */\n\n";
             $styles .= $input['styles'];
         }
         $result['styles'] = $styles;
     }
     if (isset($input['scripts'])) {
         $result['scripts'] = $input['scripts'];
     }
     return $result;
 }
 protected function getFileModificationTime($fileName)
 {
     switch (self::getFileType($fileName)) {
         case self::FILE_TYPE_REGULAR:
             return filemtime($fileName);
             break;
         case self::FILE_TYPE_SASS:
             $sass = new SassService($fileName);
             return $sass->getModificationTime();
             break;
     }
 }
Exemplo n.º 4
0
 /**
  * Get a default Sass compiler instance
  *
  * @return ExternalRubyCompiler
  */
 public static function getDefaultCompiler()
 {
     if (self::$defaultCompiler === null) {
         $app = F::app();
         self::$defaultCompiler = new ExternalRubyCompiler(array('rootDir' => $app->getGlobal('IP'), 'sassExecutable' => $app->wg->SassExecutable));
     }
     return self::$defaultCompiler;
 }
 protected function getFileModificationTime($fileName)
 {
     switch (self::getFileType($fileName)) {
         case self::FILE_TYPE_REGULAR:
             return filemtime($fileName);
             break;
         case self::FILE_TYPE_SASS:
             return SassService::newFromFile($fileName)->getModifiedTime();
             break;
     }
 }