Пример #1
0
 /**
  * @param string $themeName
  * @param string $lessFile
  * @return string
  */
 public function compileFile($themeName, $lessFile)
 {
     $model = Model::instance();
     $theme = $model->getTheme($themeName);
     $options = $theme->getOptionsAsArray();
     $configModel = ConfigModel::instance();
     $config = $configModel->getAllConfigValues($themeName);
     $less = "@import '{$lessFile}';";
     $less .= $this->generateLessVariables($options, $config);
     $css = '';
     try {
         require_once ipFile('Ip/Lib/less.php/Less.php');
         $themeDir = ipFile('Theme/' . $themeName . '/assets/');
         $ipContentDir = ipFile('Ip/Internal/Core/assets/ipContent/');
         // creating new context to pass theme assets directory dynamically to a static callback function
         $context = $this;
         $callback = function ($parseFile) use($context, $themeDir) {
             return $context->overrideImportDirectory($themeDir, $parseFile);
         };
         $parserOptions = array('import_callback' => $callback, 'cache_dir' => ipFile('file/tmp/less/'), 'relativeUrls' => false, 'sourceMap' => true);
         $parser = new \Less_Parser($parserOptions);
         $directories = array($themeDir => '', $ipContentDir => '');
         $parser->SetImportDirs($directories);
         $parser->parse($less);
         $css = $parser->getCss();
         $css = "/* Edit {$lessFile}, not this file. */" . "\n" . $css;
     } catch (\Exception $e) {
         ipLog()->error('Less compilation error: Theme - ' . $e->getMessage());
     }
     return $css;
 }
Пример #2
0
 /**
  * @param string $name
  * @param string $default
  * @param string $themeName
  * @return string
  */
 public function getThemeOption($name, $default = null, $themeName = null)
 {
     if (!$themeName) {
         $themeName = ipConfig()->theme();
     }
     $configModel = ConfigModel::instance();
     $value = $configModel->getConfigValue($themeName, $name, $default);
     return $value;
 }
Пример #3
0
 public static function ipBeforeController()
 {
     $configModel = ConfigModel::instance();
     if ($configModel->isInPreviewState()) {
         ipAddJsVariable('ipRepositoryUrl', ipFileUrl('file/repository/'));
         static::initConfig();
     }
     $lessCompiler = LessCompiler::instance();
     if (ipConfig()->isDevelopmentEnvironment()) {
         if ($lessCompiler->shouldRebuild(ipConfig()->theme())) {
             $lessCompiler->rebuild(ipConfig()->theme());
         }
     }
 }