Пример #1
0
 /**
  * @param string $path
  * @return string
  */
 protected function _compile($path)
 {
     try {
         return $this->_processor->compileFile($path);
     } catch (Exception $ex) {
         die('<strong>Less Error (JBlank):</strong><br/><pre>' . $ex->getMessage() . '</pre>');
     }
 }
Пример #2
0
 public function actionLess()
 {
     Yii::import('mod.core.models.less.*');
     if (isset($_POST['Less'])) {
         $path = Yii::getPathOfAlias('webroot.themes.default.less');
         Yii::import('app.phpless.lessc');
         $less = new lessc();
         $param = array();
         foreach ($_POST['Less'] as $key => $val) {
             $param[$key] = $val;
         }
         Yii::app()->settings->set('less', $param);
         $less->setVariables($param);
         /* $less->setVariables(array(
            'btn-default-bgcolor' => '#e0e0e0', //#e0e0e0
            'btn-primary-bgcolor' => '#265a88',
            'btn-success-bgcolor' => '#419641',
            'btn-info-bgcolor' => '#2aabd2',
            'btn-warning-bgcolor' => '#eb9316',
            'btn-danger-bgcolor' => '#c12e2a',
            )); */
         $less->compileFile($path . "/bootstrap-theme.less", Yii::getPathOfAlias('webroot.themes.default.assets.css') . "/bootstrap-theme.css");
     }
     $this->render('less', array('gradient' => new LessGradient()));
 }
Пример #3
0
 /**
  * Compile CSS files used by admin ui
  *
  * @throws Exception
  */
 protected function _compileCss()
 {
     $bootstrapPath = WWW_ROOT . 'bootstrap';
     if (!file_exists($bootstrapPath)) {
         if (!$this->_clone) {
             throw new Exception('You don\'t have "bootstrap" directory in ' . WWW_ROOT);
         }
         CakeLog::info('Cloning Bootstrap...');
         chdir(WWW_ROOT);
         exec('git clone git://github.com/twitter/bootstrap');
     }
     chdir($bootstrapPath);
     exec('git checkout -f v2.2.0');
     App::import('Vendor', 'Lessc', array('file' => 'lessphp' . DS . 'lessc.inc.php'));
     $lessc = new lessc();
     $formatter = new lessc_formatter_lessjs();
     $formatter->compressColors = false;
     ini_set('precision', 16);
     $lessc->setFormatter($formatter);
     $files = array('less' . DS . 'admin.less' => CSS . 'croogo-bootstrap.css', 'less' . DS . 'admin-responsive.less' => CSS . 'croogo-bootstrap-responsive.css');
     foreach ($files as $file => $output) {
         $out = str_replace(APP, '', $output);
         if ($lessc->compileFile(WWW_ROOT . $file, $output)) {
             $text = __('CSS : %s created', $out);
             CakeLog::info($text);
         } else {
             $text = __('CSS : %s failed', $out);
             CakeLog::error($text);
         }
     }
 }
Пример #4
0
 public function __invoke($file, $minify = null)
 {
     if (!is_file($this->getOptions()->getPublicDir() . $file)) {
         throw new \InvalidArgumentException('File "' . $this->getOptions()->getPublicDir() . $file . '" not found.');
     }
     $less = new \lessc();
     $info = pathinfo($file);
     $newFile = $this->getOptions()->getDestinationDir() . $info['filename'] . '.' . filemtime($this->getOptions()->getPublicDir() . $file) . '.css';
     $_file = $this->getOptions()->getPublicDir() . $newFile;
     if (!is_file($_file)) {
         $globPattern = $this->getOptions()->getPublicDir() . $this->getOptions()->getDestinationDir() . $info['filename'] . '.*.css';
         foreach (Glob::glob($globPattern, Glob::GLOB_BRACE) as $match) {
             if (preg_match("/^" . $info['filename'] . "\\.[0-9]{10}\\.css\$/", basename($match))) {
                 unlink($match);
             }
         }
         $compiledFile = new \SplFileObject($_file, 'w');
         $result = $less->compileFile($this->getOptions()->getPublicDir() . $file);
         if (is_null($minify) && $this->getOptions()->getMinify() || $minify === true) {
             $result = \CssMin::minify($result);
         }
         $compiledFile->fwrite($result);
     }
     return $newFile;
 }
Пример #5
0
 protected function doProcess($inputPath, $outputPath)
 {
     $this->ensureInitialized();
     if ($this->jsToolOptions === false) {
         $less = new \lessc();
         if ($this->pieCrust->isCachingEnabled()) {
             $cacheUri = 'less/' . sha1($inputPath);
             $cacheData = $this->readCacheData($cacheUri);
             if ($cacheData) {
                 $lastUpdated = $cacheData['updated'];
             } else {
                 $lastUpdated = false;
                 $cacheData = $inputPath;
             }
             $cacheData = $less->cachedCompile($cacheData);
             $this->writeCacheData($cacheUri, $cacheData);
             if (!$lastUpdated || $cacheData['updated'] > $lastUpdated) {
                 file_put_contents($outputPath, $cacheData['compiled']);
             }
         } else {
             $less->compileFile($inputPath, $outputPath);
         }
     } else {
         $exe = $this->jsToolOptions['bin'];
         $options = $this->jsToolOptions['options'];
         $cmd = "{$exe} {$options} \"{$inputPath}\" \"{$outputPath}\"";
         $this->logger->debug('$> ' . $cmd);
         shell_exec($cmd);
     }
 }
Пример #6
0
 /**
  * Parse a Less file to CSS
  */
 public function parse($src, $dst, $options)
 {
     $this->auto = isset($options['auto']) ? $options['auto'] : $this->auto;
     try {
         if ($this->auto) {
             /* @var FileCache $cacheMgr */
             $cacheMgr = Yii::createObject('yii\\caching\\FileCache');
             $cacheMgr->init();
             $cacheId = 'less#' . $dst;
             $cache = $cacheMgr->get($cacheId);
             if ($cache === false || @filemtime($dst) < @filemtime($src)) {
                 $cache = $src;
             }
             $less = new \lessc();
             $newCache = $less->cachedCompile($cache);
             if (!is_array($cache) || $newCache["updated"] > $cache["updated"]) {
                 $cacheMgr->set($cacheId, $newCache);
                 file_put_contents($dst, $newCache['compiled']);
             }
         } else {
             $less = new \lessc();
             $less->compileFile($src, $dst);
         }
     } catch (Exception $e) {
         throw new Exception(__CLASS__ . ': Failed to compile less file : ' . $e->getMessage() . '.');
     }
 }
Пример #7
0
function generate($fileout, $type, $theme_option_variations)
{
    WP_Filesystem();
    global $wp_filesystem;
    $css = "";
    $regex = array("`^([\t\\s]+)`ism" => '', "`^\\/\\*(.+?)\\*\\/`ism" => "", "`([\n\\A;]+)\\/\\*(.+?)\\*\\/`ism" => "\$1", "`([\n\\A;\\s]+)//(.+?)[\n\r]`ism" => "\$1\n", "`(^[\r\n]*|[\r\n]+)[\\s\t]*[\r\n]+`ism" => "", "/\n/i" => "");
    $compiler = new lessc();
    $compiler->setFormatter('compressed');
    $css .= $compiler->compileFile(TP_THEME_DIR . 'less/theme-options.less');
    $css .= customcss();
    $css = preg_replace(array_keys($regex), $regex, $css);
    $style = $wp_filesystem->get_contents(TP_THEME_DIR . "inc/theme-info.txt");
    // Determine whether Multisite support is enabled
    if (is_multisite()) {
        // Write Theme Info into style.css
        $wp_filesystem->put_contents($fileout . $type, $style, FS_CHMOD_FILE);
        // Write the rest to specific site style-ID.css
        $fileout = $fileout . '-' . get_current_blog_id();
        $style .= $css;
        $wp_filesystem->put_contents($fileout . $type, $style, FS_CHMOD_FILE);
    } else {
        // If this is not multisite, we write them all in style.css file
        $style .= $css;
        $wp_filesystem->put_contents($fileout . $type, $style, FS_CHMOD_FILE);
    }
}
Пример #8
0
 /**
  * Compile CSS files used by admin ui
  *
  * @throws Exception
  */
 protected function _compileCss()
 {
     $bootstrapPath = $this->_croogoWebroot . 'bootstrap';
     if (!file_exists($bootstrapPath)) {
         if (!$this->_clone) {
             throw new Exception('You don\'t have "bootstrap" directory in ' . WWW_ROOT);
         }
         chdir($this->_croogoPath);
         CakeLog::info('Cloning Bootstrap...');
         $command = sprintf('git clone -b %s %s %s', escapeshellarg($this->_tags['bootstrap']), escapeshellarg($this->_repos['bootstrap']), escapeshellarg($bootstrapPath));
         CakeLog::info("\t{$command}");
         exec($command);
     }
     chdir($bootstrapPath);
     exec(sprintf('git checkout -f %s', escapeshellarg($this->_tags['bootstrap'])));
     App::import('Vendor', 'Croogo.Lessc', array('file' => 'lessphp' . DS . 'lessc.inc.php'));
     $lessc = new lessc();
     $formatter = new lessc_formatter_lessjs();
     $formatter->compressColors = false;
     ini_set('precision', 16);
     $lessc->setFormatter($formatter);
     $files = array('less' . DS . 'admin.less' => 'css' . DS . 'croogo-bootstrap.css', 'less' . DS . 'admin-responsive.less' => 'css' . DS . 'croogo-bootstrap-responsive.css');
     foreach ($files as $file => $output) {
         $file = $this->_croogoWebroot . $file;
         $output = $this->_croogoWebroot . $output;
         $out = str_replace(APP, '', $output);
         if ($lessc->compileFile($file, $output)) {
             $text = __d('croogo', 'CSS : %s created', $out);
             CakeLog::info($text);
         } else {
             $text = __d('croogo', 'CSS : %s failed', $out);
             CakeLog::error($text);
         }
     }
 }
 public function registerLessFile($url, $media = '')
 {
     $this->hasScripts = true;
     $lessUrl = $url;
     $uniqid = md5($lessUrl);
     $lessFileName = basename($lessUrl);
     $cssFileName = preg_replace('/\\.less$/i', '', $lessFileName) . ".css";
     $tempCachePath = Yii::getPathOfAlias('application.runtime.cache') . "/yiiless/{$uniqid}";
     @mkdir($tempCachePath, 0777, true);
     $cssFilePath = "{$tempCachePath}/{$cssFileName}";
     if (preg_match('/^https?\\:\\/\\//', $lessUrl)) {
         $lessFilePath = "{$tempCachePath}/{$lessFileName}";
     } else {
         if (file_exists(Yii::getPathOfAlias('webroot') . "/{$lessUrl}")) {
             $lessFilePath = Yii::getPathOfAlias('webroot') . "/{$lessUrl}";
         } else {
             if (file_exists($lessUrl)) {
                 $lessFilePath = $lessUrl;
             } else {
                 $lessFilePath = $_SERVER['DOCUMENT_ROOT'] . "/" . $lessUrl;
             }
         }
     }
     $lessCompiler = new lessc();
     if ($this->cache === false) {
         $lessCompiler->compileFile($lessFilePath, $cssFilePath);
     } else {
         $lessCompiler->checkedCompile($lessFilePath, $cssFilePath);
     }
     $cssUrl = Yii::app()->getAssetManager()->publish($cssFilePath);
     $this->cssFiles[$cssUrl] = $media;
     $params = func_get_args();
     $this->recordCachingAction('clientScript', 'registerLessFile', $params);
     return $this;
 }
Пример #10
0
 public function run()
 {
     if (!$this->srcPath) {
         throw new \UnexpectedValueException("Please specify srcPath first.");
     }
     if (!$this->targetPath) {
         throw new \UnexpectedValueException("Please specify targetPath first.");
     }
     if (!is_dir($this->targetPath)) {
         mkdir($this->targetPath, 0777);
     }
     $lastLessEditTime = 0;
     foreach (\Nette\Utils\Finder::find("*.less")->from($this->getSrcPath()) as $file) {
         $lastLessEditTime = max($lastLessEditTime, $file->getMTime());
     }
     $lastCompileTime = 0;
     foreach (\Nette\Utils\Finder::find("*.css")->from($this->getTargetPath()) as $file) {
         $lastCompileTime = max($lastCompileTime, $file->getMTime());
     }
     $compiler = new \lessc();
     foreach ($this->getfilesMapping() as $src => $target) {
         if (!is_file($this->targetPath . "/" . $target) || $lastLessEditTime > $lastCompileTime) {
             $compiler->compileFile($this->srcPath . "/" . $src, $this->targetPath . "/" . $target);
         }
     }
 }
Пример #11
0
function CompileOptionsLess($inputFile)
{
    global $dynamo_tpl;
    require_once get_template_directory() . '/dynamo_framework/lib/lessc.inc.php';
    $less = new lessc();
    $less->setPreserveComments(true);
    $url = "'" . get_template_directory_uri() . "'";
    $body_bg_image = "'" . get_option($dynamo_tpl->name . '_body_bg_image') . "'";
    $page404_bg_image = "'" . get_option($dynamo_tpl->name . '_page404_bg_image') . "'";
    $subheader_area_bgimage = "'" . get_option($dynamo_tpl->name . '_subheader_area_bgimage') . "'";
    $branding_logo_image = "'" . get_option($dynamo_tpl->name . '_branding_logo_image') . "'";
    $expander_bgimage = "'" . get_option($dynamo_tpl->name . '_expander_bgimage') . "'";
    $footer_bg_image = "'" . get_option($dynamo_tpl->name . '_footer_bg_image') . "'";
    $expander_bgimage = "'" . get_option($dynamo_tpl->name . '_expander_bgimage') . "'";
    $footerbgtype = 'n';
    if (get_option($dynamo_tpl->name . '_footer_pattern', 'none') != 'none') {
        $footerbgtype = 'p';
    }
    if (get_option($dynamo_tpl->name . '_footer_bg_image') != '') {
        $footerbgtype = 'i';
    }
    $expanderbgtype = 'n';
    if (get_option($dynamo_tpl->name . '_expander_pattern', 'none') != 'none') {
        $expanderbgtype = 'p';
    }
    if (get_option($dynamo_tpl->name . '_expander_bgimage') != '') {
        $expanderbgtype = 'i';
    }
    $less->setVariables(array("url" => $url, "fontsize_body" => get_option($dynamo_tpl->name . '_fontsize_body', '13px'), "fontsize_h1" => get_option($dynamo_tpl->name . '_fontsize_h1', '40px'), "fontsize_h2" => get_option($dynamo_tpl->name . '_fontsize_h2', '30px'), "fontsize_h3" => get_option($dynamo_tpl->name . '_fontsize_h3', '18px'), "fontsize_h4" => get_option($dynamo_tpl->name . '_fontsize_h4', '16px'), "fontsize_h5" => get_option($dynamo_tpl->name . '_fontsize_h5', '14px'), "fontsize_h6" => get_option($dynamo_tpl->name . '_fontsize_h6', '12px'), "maincontent_accent_color" => get_option($dynamo_tpl->name . '_maincontent_accent_color', '#3296dc'), "maincontent_secondary_accent_color" => get_option($dynamo_tpl->name . '_maincontent_secondary_accent_color', '#000000'), "page_wrap_state" => get_option($dynamo_tpl->name . '_page_wrap_state', 'streched'), "page_bgcolor" => get_option($dynamo_tpl->name . '_page_bgcolor', '#ffffff'), "page_pattern" => get_option($dynamo_tpl->name . '_page_pattern', 'none'), "body_bg_image_state" => get_option($dynamo_tpl->name . '_body_bg_image_state', 'N'), "body_bg_image" => $body_bg_image, "body_bgcolor" => get_option($dynamo_tpl->name . '_body_bgcolor', '#ffffff'), "body_pattern" => get_option($dynamo_tpl->name . '_body_pattern', 'none'), "paspartu_state" => get_option($dynamo_tpl->name . '_paspartu_state', 'N'), "paspartu_bg_color" => get_option($dynamo_tpl->name . '_paspartu_bg_color', '#ffffff'), "paspartu_width" => get_option($dynamo_tpl->name . '_paspartu_width', '30') . 'px', "top_bar_bg_color" => get_option($dynamo_tpl->name . '_top_bar_bg_color', '#000000'), "top_bar_text_color" => get_option($dynamo_tpl->name . '_top_bar_text_color', '#ffffff'), "top_bar_link_color" => get_option($dynamo_tpl->name . '_top_bar_link_color', '#3296dc'), "top_bar_hlink_color" => get_option($dynamo_tpl->name . '_top_bar_hlink_color', '#f2f2f2'), "top_bar_icon_color" => get_option($dynamo_tpl->name . '_top_bar_icon_color', '#ffffff'), "branding_logo_type" => get_option($dynamo_tpl->name . '_branding_logo_type'), "branding_logo_image" => $branding_logo_image, "branding_logo_image_width" => get_option($dynamo_tpl->name . '_branding_logo_image_width', '160') . 'px', "branding_logo_image_height" => get_option($dynamo_tpl->name . '_branding_logo_image_height', '50') . 'px', "branding_logo_top_margin" => get_option($dynamo_tpl->name . '_branding_logo_top_margin', '30') . 'px', "branding_logo_bottom_margin" => get_option($dynamo_tpl->name . '_branding_logo_bottom_margin', '10') . 'px', "sticky_logo_top_margin" => get_option($dynamo_tpl->name . '_sticky_logo_top_margin', '10') . 'px', "menu_top_bg_color" => get_option($dynamo_tpl->name . '_menu_top_bg_color', 'transparent'), "top_mainmenu_link_color" => get_option($dynamo_tpl->name . '_top_mainmenu_link_color', '#222222'), "top_mainmenu_hlink_color" => get_option($dynamo_tpl->name . '_top_mainmenu_hlink_color', '#3296dc'), "sticky_header_bgcolor" => get_option($dynamo_tpl->name . '_sticky_header_bgcolor', 'rgba(255,255,255,0.95)'), "sticky_mainmenu_link_color" => get_option($dynamo_tpl->name . '_sticky_mainmenu_link_color', '#222222'), "sticky_mainmenu_hlink_color" => get_option($dynamo_tpl->name . '_sticky_mainmenu_hlink_color', '#3296dc'), "aside_logo_image_width" => get_option($dynamo_tpl->name . '_aside_logo_image_width', '101') . 'px', "aside_logo_image_height" => get_option($dynamo_tpl->name . '_aside_logo_image_height', '35') . 'px', "aside_mainmenu_bg_color" => get_option($dynamo_tpl->name . '_aside_mainmenu_bg_color', '#ffffff'), "aside_mainmenu_link_color" => get_option($dynamo_tpl->name . '_aside_mainmenu_link_color', '#222222'), "aside_mainmenu_hlink_color" => get_option($dynamo_tpl->name . '_aside_mainmenu_hlink_color', '#3296dc'), "submenu_bgcolor" => get_option($dynamo_tpl->name . '_submenu_bgcolor', '#ffffff'), "submenu_topbordercolor" => get_option($dynamo_tpl->name . '_submenu_topbordercolor', '#3296dc'), "submenu_link_color" => get_option($dynamo_tpl->name . '_submenu_link_color', '#AFB4B9'), "submenu_hlink_color" => get_option($dynamo_tpl->name . '_submenu_hlink_color', '#AFB4B9'), "submenu_hbg_color" => get_option($dynamo_tpl->name . '_submenu_hbg_color', '#F6F6F6'), "overlay_mainmenu_bg_color" => get_option($dynamo_tpl->name . '_overlay_mainmenu_bg_color', '#ffffff'), "overlay_mainmenu_link_color" => get_option($dynamo_tpl->name . '_overlay_mainmenu_link_color', '#222222'), "overlay_mainmenu_hlink_color" => get_option($dynamo_tpl->name . '_overlay_mainmenu_hlink_color', '#3296dc'), "overlay_mainmenu_bg_color" => get_option($dynamo_tpl->name . '_overlay_mainmenu_bg_color', '#ffffff'), "overlay_mainmenu_link_color" => get_option($dynamo_tpl->name . '_overlay_mainmenu_link_color', '#222222'), "overlay_mainmenu_hlink_color" => get_option($dynamo_tpl->name . '_overlay_mainmenu_hlink_color', '#3296dc'), "overlapping_header_bgcolor" => get_option($dynamo_tpl->name . '_overlapping_header_bgcolor', '#ffffff'), "overlapping_mainmenu_link_color_light" => get_option($dynamo_tpl->name . '_overlapping_mainmenu_link_color_light', '#ffffff'), "overlapping_mainmenu_hlink_color_light" => get_option($dynamo_tpl->name . '_overlapping_mainmenu_hlink_color_light', '#3296dc'), "overlapping_mainmenu_link_color_dark" => get_option($dynamo_tpl->name . '_overlapping_mainmenu_link_color_dark', '#222222'), "overlapping_mainmenu_hlink_color_dark" => get_option($dynamo_tpl->name . '_overlapping_mainmenu_hlink_color_dark', '#3296dc'), "subheader_bgcolor" => get_option($dynamo_tpl->name . '_subheader_bgcolor', '#F7F8FA'), "subheader_pattern" => get_option($dynamo_tpl->name . '_subheader_pattern', 'none'), "subheader_area_bgimage" => $subheader_area_bgimage, "subheader_text_color" => get_option($dynamo_tpl->name . '_subheader_text_color', '#ffffff'), "expander_bgcolor" => get_option($dynamo_tpl->name . '_expander_bgcolor', '#222222'), "expander_bgimage" => $expander_bgimage, "expander_pattern" => get_option($dynamo_tpl->name . '_expander_pattern', 'none'), "expander_text_color" => get_option($dynamo_tpl->name . '_eexpander_text_color', '#ffffff'), "expander_link_color" => get_option($dynamo_tpl->name . '_expander_link_color', '#3296dc'), "expander_hlink_color" => get_option($dynamo_tpl->name . '_expander_hlink_color', '#f6f6f6'), "expanderbgtype" => $expanderbgtype, "maincontent_text_color" => get_option($dynamo_tpl->name . '_maincontent_text_color', '#7A7A7A'), "maincontent_headers_color" => get_option($dynamo_tpl->name . '_maincontent_headers_color', '#7A7A7A'), "maincontent_link_color" => get_option($dynamo_tpl->name . '_maincontent_link_color', '#3296dc'), "maincontent_hlink_color" => get_option($dynamo_tpl->name . '_maincontent_hlink_color', '#76797C'), "footer_bg_color" => get_option($dynamo_tpl->name . '_footer_bg_color', '#232D37'), "footer_bg_image" => $footer_bg_image, "footer_pattern" => get_option($dynamo_tpl->name . '_footer_pattern', 'none'), "footer_text_color" => get_option($dynamo_tpl->name . '_footer_text_color', '#BCC1C5'), "footer_header_color" => get_option($dynamo_tpl->name . '_footer_header_color', '#ffffff'), "footer_link_color" => get_option($dynamo_tpl->name . '_footer_link_color', '#ffffff'), "footer_hlink_color" => get_option($dynamo_tpl->name . '_footer_hlink_color', '#3296dc'), "footerbgtype" => $footerbgtype, "copyrightbgcolor" => get_option($dynamo_tpl->name . '_copyright_bg_color', 'rgba(0,0,0,.2)'), "copyrightbordercolor" => get_option($dynamo_tpl->name . '_copyright_border_color', 'rgba(0,0,0,0)'), "copyrighttextcolor" => get_option($dynamo_tpl->name . '_copyright_text_color', '#A2A2A2'), "copyrightlinkcolor" => get_option($dynamo_tpl->name . '_copyright_link_color', '#A2A2A2'), "copyrighthlinkcolor" => get_option($dynamo_tpl->name . '_copyright_hlink_color', '#fff'), "page404_bg_image" => $page404_bg_image, "page404_bg_image_state" => get_option($dynamo_tpl->name . '_404_bg_image_state', 'N')));
    $less->compileFile(get_template_directory() . '/css/less/' . $inputFile, get_template_directory() . '/css/dynamic.css');
}
Пример #12
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ('development' != $input->getArgument('environment') && 'production' != $input->getArgument('environment')) {
         return $output->writeln($input->getArgument('environment') . ' environment not found');
     }
     $jsMinifier = new JS();
     $cssMinifier = new CSS();
     $output->writeln('Building environment: ' . $input->getArgument('environment'));
     $output->write('Generating JavaScript build file...');
     $jsFiles = FileSystem::listDirectoryRecursive(Application::webRoot() . '/js', '/^.+\\.js$/i');
     $buildFile = fopen(Application::webRoot() . '/min/build.js', 'w');
     foreach ($jsFiles as $filePath) {
         fwrite($buildFile, file_get_contents($filePath) . "\n\n");
     }
     fclose($buildFile);
     $output->writeln('done');
     $output->write('Shrinking JavaScript...');
     $jsMinifier->add(Application::webRoot() . '/min/build.js');
     $jsMinifier->minify(Application::webRoot() . '/min/build.min.js');
     $output->writeln('done');
     $output->write('Compiling less files...');
     $less = new \lessc();
     $less->compileFile(Application::webRoot() . '/media/importer.less', Application::webRoot() . '/min/build.css');
     $output->writeln('done');
     $output->write('Shrinking css files...');
     $cssMinifier->add(Application::webRoot() . '/min/build.css');
     $cssMinifier->minify(Application::webRoot() . '/min/build.min.css');
     $output->writeln('done');
     return null;
 }
Пример #13
0
 /**
  * @param FileContainer $file
  *
  * @return $this
  * @throws CompilerException
  */
 protected function compileLESS(FileContainer $file)
 {
     try {
         return $file->setOutputContent($this->less->compileFile($file->getInputPath()));
     } catch (\Exception $e) {
         throw new CompilerException($e->getMessage(), 1, $e);
     }
 }
Пример #14
0
 /**
  * Compile the LESS at the given path.
  *
  * @param  string  $path
  * @return void
  */
 public function compile($path)
 {
     $less = new \lessc();
     $contents = $less->compileFile($path);
     if (!is_null($this->cachePath)) {
         $this->files->put($this->getCompiledPath($path), $contents);
     }
 }
Пример #15
0
function generate_less_css()
{
    include_once __DIR__ . '/../vendor/lessc.inc.php';
    $less = new lessc();
    $less->setFormatter("compressed");
    $less_file = __DIR__ . "/../less/site.less";
    $css_file = __DIR__ . "/../css/style.css";
    return $less->compileFile($less_file, $css_file);
}
Пример #16
0
 public static function parse($source, $isFile = true)
 {
     $parser = new lessc();
     try {
         return $isFile ? $parser->compileFile($source) : $parser->compile($source);
     } catch (Exception $e) {
         return '/** LESS PARSE ERROR: ' . $e->getMessage() . ' **/';
     }
 }
Пример #17
0
 public static function build(Event $event)
 {
     $base = __DIR__ . '/../../../../vendor/twitter/bootstrap';
     if (!file_exists($base . '/css')) {
         mkdir($base . '/css');
         $compiler = new \lessc();
         $compiler->compileFile("{$base}/less/bootstrap.less", "{$base}/css/bootstrap.css");
     }
 }
 /**
  * Compile less -> css 
  * @param str $inputFile
  * @param str $outputFile
  * @return boolean
  */
 public static function less($inputFile, $outputFile)
 {
     if (JFile::exists($inputFile)) {
         $less = new lessc();
         $less->setImportDir(array(dirname($inputFile)));
         return $less->compileFile($inputFile, $outputFile);
     }
     return false;
 }
Пример #19
0
 public static function compile($source, $dest)
 {
     $sourceFile = new File(DIR_CSS . '/' . $source);
     $destFile = new File(DIR_CSS . '/' . $dest);
     if (self::checkIfNeedCompile($sourceFile, $destFile)) {
         require_once "lessc.inc.php";
         $less = new \lessc();
         $less->compileFile($sourceFile->path, $destFile->path);
     }
 }
Пример #20
0
function Core_View_Helper_Css($files)
{
    include_once LIBRARY_PATH . '/Less/lessc.inc.php';
    $options = Core_Resource_View::getOptions();
    $less = new lessc();
    foreach ($files as $key => $file) {
        if (substr($file, 0, 1) != '/') {
            $filePaths[] = APPLICATION_PATH . '/theme/' . $options['theme'] . '/' . $file;
        } else {
            $filePaths[] = BASE_PATH . $file;
        }
    }
    if ($options['combineCss']) {
        $fileDate = 0;
        $cacheFile = '';
        foreach ($filePaths as $filePath) {
            $fileDate = max(filemtime($filePath), $fileDate);
            $cacheFile .= $filePath;
        }
        $cacheFile = md5($cacheFile) . '.css';
        $cacheFilePath = BASE_PATH . '/public/cache/' . $cacheFile;
        $cacheFileDate = file_exists($cacheFilePath) ? filemtime($cacheFilePath) : 0;
        if ($cacheFileDate < $fileDate) {
            $fileContent = '';
            $less->setVariables(array('themeUrl' => "'" . BASE_URL . '/app/theme/' . $options['theme'] . "'", 'publicUrl' => "'" . BASE_URL . '/public' . "'"));
            foreach ($filePaths as $filePath) {
                $ext = pathinfo($filePath, PATHINFO_EXTENSION);
                if ($ext == 'less') {
                    $fileContent .= $less->compileFile($filePath) . PHP_EOL;
                } else {
                    $fileContent .= file_get_contents($filePath) . PHP_EOL;
                }
            }
            file_put_contents($cacheFilePath, $options['minify'] ? Core_Helper_Minify::minifyCss($fileContent) : $fileContent);
        }
        $fileLinks = array(BASE_URL . '/public/cache/' . $cacheFile);
    } else {
        foreach ($filePaths as $key => $filePath) {
            $ext = pathinfo($filePath, PATHINFO_EXTENSION);
            if ($ext == 'less') {
                $less->setVariables(array('themeUrl' => "'" . BASE_URL . '/app/theme/' . $options['theme'] . "'"));
                $cacheFile = md5($filePath) . '.css';
                $cacheFilePath = BASE_PATH . '/public/cache/' . $cacheFile;
                $less->checkedCompile($filePath, $cacheFilePath);
                $fileLinks[] = BASE_URL . '/public/cache/' . $cacheFile;
            } else {
                $fileLinks[] = BASE_URL . '/' . trim(str_replace(BASE_PATH, '', $filePath), '/');
            }
        }
    }
    foreach ($fileLinks as $link) {
        echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$link}\" />" . PHP_EOL;
    }
}
Пример #21
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $in = $this->normalizePath($input->getArgument('fileIn'));
     $out = $this->normalizePath($input->getArgument('fileOut'));
     $less = new \lessc();
     try {
         $less->compileFile($in, $out);
     } catch (\Exception $e) {
         $output->writeln("<error>fatal error: {$e->getMessage()}</error>");
     }
 }
Пример #22
0
 function test($data)
 {
     require "scripts/lessc.inc.php";
     $less = new lessc();
     if (ENVIRONMENT != 'development') {
         $less->checkedCompile('content/' . $data . '/style_compilator.less', 'content/cache/' . $data . '_compiled.css');
     } else {
         $less->compileFile('content/' . $data . '/style_compilator.less', 'content/cache/' . $data . '_compiled.css');
     }
     echo '<link href="/content/cache/' . $data . '_compiled.css" rel="stylesheet" type="text/css" />';
 }
Пример #23
0
 /**
  * Builds a LESS/CSS resource from a file
  *
  * @param string $path
  * The path to a CSS/LESS file
  *
  * @return type
  * The final compressed CSS
  */
 public static function buildFile($path)
 {
     $obj = new \lessc();
     $obj->setFormatter('compressed');
     try {
         $output = $obj->compileFile($path);
     } catch (\Exception $e) {
         throw $e;
     }
     return $output;
 }
Пример #24
0
function ImportLESS($path)
{
    require $_SERVER['DOCUMENT_ROOT'] . "/lib/less/lessc.inc.php";
    $less = new lessc();
    $buffer = $less->compileFile($_SERVER['DOCUMENT_ROOT'] . $path);
    $buffer = preg_replace('!/\\*[^*]*\\*+([^/][^*]*\\*+)*/!', '', $buffer);
    // Remove space after colons
    $buffer = str_replace(': ', ':', $buffer);
    // Remove whitespace
    $buffer = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), '', $buffer);
    echo "<style>{$buffer}</style>" . PHP_EOL;
}
Пример #25
0
 public static function build(Event $event)
 {
     if (class_exists('lessc')) {
         // this can get called before composer has installed all the packages
         $base = __DIR__ . '/../../../../vendor/twitter/bootstrap';
         if (!file_exists($base . '/css')) {
             mkdir($base . '/css');
             $compiler = new \lessc();
             $compiler->compileFile("{$base}/less/bootstrap.less", "{$base}/css/bootstrap.css");
         }
     }
 }
Пример #26
0
function compileChildLessFile($input, $output, $params)
{
    $less = new lessc();
    $less->setVariables($params);
    // input and output location
    $inputFile = get_stylesheet_directory() . '/less/' . $input;
    $outputFile = get_stylesheet_directory() . '/css/' . $output;
    try {
        $less->compileFile($inputFile, $outputFile);
    } catch (Exception $ex) {
        echo "lessphp fatal error: " . $ex->getMessage();
    }
}
Пример #27
0
 private function finalizePackage($package)
 {
     $fs = new FileSystem();
     $base = $this->getPackageBasePath($package);
     $fs->ensureDirectoryExists("{$base}/css");
     $compiler = new \lessc();
     $compiler->compileFile("{$base}/less/tiki.less", "{$base}/css/{$base}.css");
     // Clean-up undesired files
     $fs->remove("{$base}/dist");
     $fs->remove("{$base}/docs");
     $fs->remove("{$base}/grunt");
     $fs->remove("{$base}/js");
     $fs->remove("{$base}/test-infra");
 }
Пример #28
0
 /**
  * Parse a Less file to CSS
  */
 public function parse($src, $dst, $options)
 {
     $this->auto = isset($options['auto']) ? $options['auto'] : $this->auto;
     $variables = $this->variables;
     $assetManager = Yii::$app->assetManager;
     // Final url of the file being compiled
     $assetUrl = substr($dst, strpos($assetManager->basePath, $assetManager->baseUrl));
     $variables['published-url'] = '"' . $assetUrl . '"';
     // Root for the published folder
     $variables['published-base-url'] = '"/' . implode('/', array_slice(explode('/', ltrim($assetUrl, '/')), 0, 2)) . '"';
     $less = new \lessc();
     $less->setVariables($variables);
     // Compressed setting
     if ($this->compressed) {
         $less->setFormatter('compressed');
     }
     \Less_Parser::$default_options['compress'] = $this->compressed;
     \Less_Parser::$default_options['relativeUrls'] = $this->relativeUrls;
     // Send out pre-compile event
     $event = new \yii\base\Event();
     $this->runtime = ['sourceFile' => $src, 'destinationFile' => $dst, 'compiler' => $less];
     $event->sender = $this;
     Event::trigger($this, self::EVENT_BEFORE_COMPILE, $event);
     try {
         if ($this->auto) {
             /* @var FileCache $cacheMgr */
             $cacheMgr = Yii::createObject('yii\\caching\\FileCache');
             $cacheMgr->init();
             $cacheId = 'less#' . $dst;
             $cache = $cacheMgr->get($cacheId);
             if ($cache === false || @filemtime($dst) < @filemtime($src)) {
                 $cache = $src;
             }
             $newCache = $less->cachedCompile($cache);
             if (!is_array($cache) || $newCache["updated"] > $cache["updated"]) {
                 $cacheMgr->set($cacheId, $newCache);
                 file_put_contents($dst, $newCache['compiled']);
             }
         } else {
             $less->compileFile($src, $dst);
         }
         // If needed, respect the users configuration
         if ($assetManager->fileMode !== null) {
             @chmod($dst, $assetManager->fileMode);
         }
         unset($this->less);
     } catch (\Exception $e) {
         throw new \Exception(__CLASS__ . ': Failed to compile less file : ' . $e->getMessage() . '.');
     }
 }
Пример #29
0
 protected function _getInlineCSS()
 {
     $s = '';
     require_once $this->_sDirPlugins . 'lessphp/lessc.inc.php';
     $oLess = new lessc();
     $oConfigBase = new BxBaseConfig();
     $oLess->setVariables($oConfigBase->aLessConfig);
     foreach ($this->_aFilesCss as $sFile) {
         if (substr($sFile, -5) !== '.less') {
             continue;
         }
         $s .= $oLess->compileFile($this->_sPathCss . $sFile) . "\n";
     }
     return $s;
 }
Пример #30
0
    public function filter(\Nette\Latte\MacroNode $node, $writer)
    {
        $path = $node->tokenizer->fetchWord();
        $params = $writer->formatArray();
        $path = $this->moduleHelpers->expandPath($path, 'Resources/public');
        $path = \Nette\Utils\Strings::replace($path, '~\\\\~', '/');
        if (!$this->debugMode) {
            $less = new \lessc();
            $file = new \SplFileInfo($path);
            $targetFile = $file->getBasename() . '-' . md5($path . filemtime($path)) . '.css';
            $targetDir = $this->wwwCacheDir . '/less';
            $target = $targetDir . '/' . $targetFile;
            $targetUrl = substr($target, strlen($this->wwwDir));
            if (!file_exists($targetDir)) {
                umask(00);
                mkdir($targetDir, 0777, true);
            }
            $less->compileFile($path, $target);
            return '$control->getPresenter()->getContext()->getService("assets.assetManager")->addStylesheet("' . $targetUrl . '", ' . $params . '); ';
        } else {
            return '
				$_less_file = new \\SplFileInfo("' . $path . '");
				$_less_targetFile = $_less_file->getBasename() .  \'-\' . md5(\'' . $path . '\') . \'-\' . md5(\'' . $path . '\' . filemtime("' . $path . '")) . \'.css\';
				$_less_targetDir = \'' . $this->wwwCacheDir . '/less\';
				$_less_target = $_less_targetDir  . \'/\' . $_less_targetFile;
				$_less_targetUrl = substr($_less_target, strlen(\'' . $this->wwwDir . '\'));

				if (!file_exists($_less_target)) {
					$_less = new \\lessc();
					if (!file_exists($_less_targetDir)) {
						umask(0000);
						mkdir($_less_targetDir, 0777, true);
					}

					// Remove old files
					foreach (\\Nette\\Utils\\Finder::findFiles($_less_file->getBasename() . \'-\' . md5(\'' . $path . '\') . \'-*\')->from($_less_targetDir) as $_less_old) {
						unlink($_less_old->getPathname());
					}

					$_less->compileFile(\'' . $path . '\', $_less_target);
				}

				$control->getPresenter()->getContext()->getService("assets.assetManager")->addStylesheet($_less_targetUrl, ' . $params . ');
			';
        }
    }