/** * Filters an asset just before it's dumped. * * @param AssetInterface $asset */ public function filterDump(AssetInterface $asset) { $this->dispatch(new LoadThemeVariables($variables = new Collection())); $compiler = new Compiler(); if ($dir = $asset->getSourceDirectory()) { $compiler->addImportPath($dir); } $compiler->setVariables($variables->all()); $asset->setContent($this->parser->parse($compiler->compile($asset->getContent()))); }
public function getBlocks() { $parameters = $this->request->route()->parameters(); $scssSource = file_get_contents(public_path() . $this->request->input('themeFolder') . $parameters['theme'] . "/style.scss"); // complile scss $scss = new Compiler(); $scss->setVariables($this->request->input('settings')); $css = $scss->compile($scssSource); $header = file_get_contents(public_path() . $this->request->input('themeFolder') . $parameters['theme'] . "/header.html"); $footer = file_get_contents(public_path() . $this->request->input('themeFolder') . $parameters['theme'] . "/footer.html"); // include css in header $header = str_replace('/* --INCLUDE CSS-- */', $css, $header); return response()->json(['status' => 'success', 'header' => $header, 'footer' => $footer]); }
public function filterLoad(AssetInterface $asset) { $sc = new Compiler(); if ($this->compass) { new \scss_compass($sc); } if ($dir = $asset->getSourceDirectory()) { $sc->addImportPath($dir); } foreach ($this->importPaths as $path) { $sc->addImportPath($path); } foreach ($this->customFunctions as $name => $callable) { $sc->registerFunction($name, $callable); } if ($this->formatter) { $sc->setFormatter($this->formatter); } if (!empty($this->variables)) { $sc->setVariables($this->variables); } $asset->setContent($sc->compile($asset->getContent())); }
/** * Returns the URL to the less/css-compiled file. * * @return string */ private function getLessUrl() { $p = $this->framework->getRootDir() . "static/" . $this->module->getPathName() . "/css/"; if (!$this->filesystem->exists($p)) { $this->filesystem->mkdir($p); } $cssfile = $p . "all.css"; $cssurl = $this->rootUrl . "static/" . $this->module->getPathName() . "/css/all.css"; // in case we have it in cache just return the url if ($this->filesystem->exists($cssfile) && !$this->isCacheDue()) { return $cssurl; } // if not go through all the dirs $dirs = $this->framework->getTemplateDirs(); // our output $allLess = ""; // paths with potential scss/less files $paths = array(); // go through all the dirs to find the all.less foreach ($dirs as $dir_) { $file = $dir_ . $this->module->getPathName() . "/_public/" . $this->framework->getTheme()->getCssCompiler() . "/all." . $this->framework->getTheme()->getCssCompiler(); if ($this->filesystem->exists($file)) { $paths[] = $dir_ . $this->module->getPathName() . "/_public/" . $this->framework->getTheme()->getCssCompiler() . "/"; $allLess = $file; break; } } // if there is none just return an empty string if ($allLess == "") { return ""; } try { $c = $this->framework->getTheme()->getCssCompiler(); if ($c == "less" || $c == "") { // the less parser $parser = new \Less_Parser(); $vars = array(); foreach ($this->getTemplateVars() as $k => $v) { if (!is_object($v) && !is_array($v)) { $vars[$k] = '\'' . $v . '\''; } } // are we minifying? \Less_Parser::$options['compress'] = $this->minifyCss; $parser->ModifyVars($vars); // parse our output $parser->parseFile($allLess, $this->rootUrl . 'static/' . $this->module->getPathName()); // and get it as css $css = $parser->getCss(); } else { if ($c == "scss") { $vars = array(); foreach ($this->getTemplateVars() as $k => $v) { if (!is_object($v) && !is_array($v)) { $vars[$k] = '' . $v . ''; } } $scss = new Compiler(); $scssData = file_get_contents($allLess); $scss->setImportPaths($paths); $scss->setVariables($vars); if ($this->minifyCss) { $scss->setFormatter("Leafo\\ScssPhp\\Formatter\\Crunched"); } else { $scss->setFormatter("Leafo\\ScssPhp\\Formatter\\Expanded"); } $css = $scss->compile($scssData); } else { if ($c == "css") { // TODO: Load all css files and just put them together in one file. } } } } catch (\Exception $e) { throw $e; } // remove the file if it exists if ($this->filesystem->exists($cssfile)) { $this->filesystem->remove($cssfile); } // save our output here $this->filesystem->dumpFile($cssfile, $css); // and return the url return $cssurl; }
/** * Compile the SCSS into CSS */ function _common_tinymce_compile_css() { require COMMON_TINYMCE_STYLES_PATH . '/vendor/autoload.php'; $scss = new Compiler(); $scss->setVariables(array('accent-color' => get_theme_mod('common_tinymce_button_color', '#999999'), 'alt-color' => get_theme_mod('common_tinymce_alt_button_color', '#CCCCCC'), 'message-color' => get_theme_mod('common_tinymce_message_color', '#BB0000'), 'warning-color' => get_theme_mod('common_tinymce_warning_color', '#CC0000'))); $css = file_get_contents(COMMON_TINYMCE_STYLES_PATH . '/assets/css/editor-styles.scss'); $css = $scss->compile($css); file_put_contents(COMMON_TINYMCE_STYLES_PATH . '/assets/css/editor-styles.css', $css); do_action('common_tinymce_compile_css', $scss); update_option('common_tinymce_styles_stylesheet', time()); }