setFormatter() public méthode

Set formatter
public setFormatter ( string $formatterName )
$formatterName string
Exemple #1
0
 public function setProductionMode($isProduction)
 {
     if ($isProduction) {
         $this->compiler->setLineNumberStyle(0);
         $this->compiler->setFormatter(CompressedOutput::class);
     }
 }
 /**
  * @param LeafoCompiler $compiler
  * @return LeafoScssProcessor
  */
 public function setCompiler(LeafoCompiler $compiler)
 {
     $compiler->setImportPaths($this->importPaths);
     $compiler->setFormatter($this->getFormatter());
     $compiler->setLineNumberStyle($this->getLineNumberStyle());
     $this->compiler = $compiler;
     return $this;
 }
 /**
  * @param string $rootScssDirectory
  * @param TwigThemeConfig $themeConfig
  * @param string | null $formatter
  * @param string | null $cacheDir
  */
 public function __construct($rootScssDirectory, TwigThemeConfig $themeConfig, $formatter = 'compressed', $cacheDir = null)
 {
     $scssImportPaths = $themeConfig->getScssImportPaths();
     $scssCompiler = new Compiler();
     $scssCompiler->setImportPaths($scssImportPaths);
     $this->salt = $formatter . $rootScssDirectory . json_encode($scssImportPaths);
     switch ($formatter) {
         case 'expanded':
             $scssCompiler->setFormatter(\Leafo\ScssPhp\Formatter\Expanded::class);
             break;
         case 'compact':
             $scssCompiler->setFormatter(\Leafo\ScssPhp\Formatter\Compact::class);
             break;
         case 'compressed':
             $scssCompiler->setFormatter(\Leafo\ScssPhp\Formatter\Compressed::class);
             break;
     }
     $this->server = new Server($rootScssDirectory, $cacheDir, $scssCompiler);
     $this->server->showErrorsAsCSS(true);
 }
 /**
  * @param string $formatter
  *
  * @throws CompilerException
  */
 public function processFiles($formatter)
 {
     $this->scss->setFormatter($this->getFormatterClass($formatter));
     $this->io->write("<info>use '{$formatter}' formatting</info>");
     foreach ($this->files as $file) {
         $this->io->write("<info>processing</info>: {$file->getInputPath()}");
         $this->fetchInputContextIntoFile($file);
         try {
             $this->processFile($file);
         } catch (CompilerException $e) {
             $this->io->writeError("<error>failed to process: {$file->getOutputPath()}</error>");
         }
     }
 }
Exemple #5
0
 public static function compileFile(string $file, array $paths, string $formatter, bool $lineComments) : array
 {
     $location = static::resolveFile($file, $paths);
     $compiler = new Compiler();
     $compiler->setImportPaths(\dirname($location));
     $compiler->addImportPath(function (string $path) use($paths) {
         return static::resolveFile($path, $paths);
     });
     $compiler->setFormatter($formatter);
     if ($lineComments) {
         $compiler->setLineNumberStyle(Compiler::LINE_COMMENTS);
     }
     $css = $compiler->compile(\file_get_contents($location), $location);
     return [$css, $compiler->getParsedFiles()];
 }
Exemple #6
0
 public function compile()
 {
     // go on even if user "stops" the script by closing the browser, closing the terminal etc.
     ignore_user_abort(true);
     // set script running time to unlimited
     set_time_limit(0);
     $root_dir = $this->root_dir;
     $scss_compiler = new Compiler();
     $scss_compiler->setNumberPrecision(10);
     $scss_compiler->stripComments = $this->strip_comments;
     $scss_compiler->addImportPath(function ($path) use($root_dir) {
         $path = $root_dir . $path . '.scss';
         $path_parts = pathinfo($path);
         $underscore_file = $path_parts['dirname'] . '/_' . $path_parts['basename'];
         if (file_exists($underscore_file)) {
             $path = $underscore_file;
         }
         if (!file_exists($path)) {
             return null;
         }
         return $path;
     });
     // set the path to your to-be-imported mixins. please note: custom paths are coming up on future releases!
     //$scss_compiler->setImportPaths($scss_folder);
     // set css formatting (normal, nested or minimized), @see http://leafo.net/scssphp/docs/#output_formatting
     $scss_compiler->setFormatter($this->formatter);
     // get .scss's content, put it into $string_sass
     $string_sass = '';
     if (is_array($this->scss_file)) {
         foreach ($this->scss_file as $scss_file) {
             $string_sass .= file_get_contents($scss_file);
         }
     } else {
         $string_sass = file_get_contents($this->scss_file);
     }
     // try/catch block to prevent script stopping when scss compiler throws an error
     try {
         // compile this SASS code to CSS
         $string_css = $scss_compiler->compile($string_sass) . "\n";
         // $string_css = csscrush_string($string_css, $options = array('minify' => true));
         // write CSS into file with the same filename, but .css extension
         file_put_contents($this->css_file, $string_css);
     } catch (Exception $e) {
         // here we could put the exception message, but who cares ...
         echo $e->getMessage();
         exit;
     }
 }
 /**
  * Compile the SCSS
  * @param \Contao\ThemeModel
  * @param boolean
  */
 public static function compile(\Contao\ThemeModel $objTheme, $blnForce = false)
 {
     if (!self::confirmDependencies()) {
         return;
     }
     //Get file key
     $strKey = self::getKey($objTheme);
     //Set file path
     $strCSSPath = 'assets/foundation/css/' . $strKey . '.css';
     //Compile the scss
     if (!file_exists(TL_ROOT . '/' . $strCSSPath) || $blnForce) {
         //Gather up the SCSS files in the assets/foundation/scss folder
         //This allows to work with different configs and edit defaults
         //Without affecting the original source
         $strBasePath = COMPOSER_DIR_RELATIVE . '/vendor/zurb/foundation/scss';
         $strCopyPath = 'assets/foundation/scss/' . $strKey;
         //Create new folder if not exists and clean it out
         $objNew = new \Folder($strCopyPath);
         $objNew->purge();
         $objOriginal = new \Folder($strBasePath);
         $objOriginal->copyTo($strCopyPath);
         //Apply the config
         self::applyConfig($objTheme, $strCopyPath);
         $strFoundationCSS = '';
         $strNormalizeCSS = '';
         //Create the SCSS compiler
         if (class_exists('scssc')) {
             $objCompiler = new \scssc();
             $objCompiler->setImportPaths(TL_ROOT . '/' . $strCopyPath);
             $objCompiler->setFormatter(\Config::get('debugMode') ? 'scss_formatter' : 'scss_formatter_compressed');
         } else {
             $objCompiler = new Compiler();
             $objCompiler->setImportPaths(TL_ROOT . '/' . $strCopyPath);
             $objCompiler->setFormatter(\Config::get('debugMode') ? 'Leafo\\ScssPhp\\Formatter\\Expanded' : 'Leafo\\ScssPhp\\Formatter\\Compressed');
         }
         $strFoundationContent = file_get_contents(TL_ROOT . '/' . $strCopyPath . '/foundation.scss');
         $strNormalizeContent = file_get_contents(TL_ROOT . '/' . $strCopyPath . '/normalize.scss');
         //Compile
         $strFoundationCSS = $objCompiler->compile($strFoundationContent);
         $strNormalizeCSS = $objCompiler->compile($strNormalizeContent);
         //Write to single CSS file cache
         $objFile = new \File($strCSSPath);
         $objFile->write($strNormalizeCSS . "\n" . $strFoundationCSS);
         $objFile->close();
     }
     return $strCSSPath;
 }
Exemple #8
0
 /**
  * @param string $name
  * @param string $scss
  * @param string $css
  * @param mixed  $style
  *
  * @dataProvider provideTests
  */
 public function testTests($name, $scss, $css, $style)
 {
     static $init = false;
     if (!getenv('TEST_SCSS_COMPAT')) {
         if (!$init) {
             $init = true;
             $this->markTestSkipped('Define TEST_SCSS_COMPAT=1 to enable ruby scss compatibility tests');
         }
         return;
     }
     $compiler = new Compiler();
     $compiler->setFormatter('Leafo\\ScssPhp\\Formatter\\' . ($style ? ucfirst($style) : 'Nested'));
     $actual = $compiler->compile($scss);
     $this->assertEquals($css, $actual, $name);
     // TODO: need to fix this in the formatters
     //$this->assertEquals(trim($css), trim($actual), $name);
 }
 /**
  * {@inheritdoc}
  */
 public function compile($path, $relativePath)
 {
     $this->parsedFiles = array();
     $scss = new Compiler();
     $scss->setFormatter('Leafo\\ScssPhp\\Formatter\\Compressed');
     if (!empty($this->importDirs)) {
         $scss->setImportPaths($this->importDirs);
     }
     $content = $this->overrideVariables();
     $content .= '@import "' . $relativePath . '";' . "\n";
     $css = $scss->compile($content);
     $parsedFiles = array();
     foreach ($scss->getParsedFiles() as $file => $time) {
         $parsedFiles[] = $file;
     }
     $this->parsedFiles = $parsedFiles;
     return $css;
 }
 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()));
 }
Exemple #11
0
 /**
  * Handle SCSS/LESS files
  *
  * @param string $content The file content
  * @param array  $arrFile The file array
  *
  * @return string The modified file content
  */
 protected function handleScssLess($content, $arrFile)
 {
     if ($arrFile['extension'] == self::SCSS) {
         $objCompiler = new Compiler();
         $objCompiler->setImportPaths(array(TL_ROOT . '/' . dirname($arrFile['name']), TL_ROOT . '/vendor/contao-components/compass/css'));
         $objCompiler->setFormatter(\Config::get('debugMode') ? 'Leafo\\ScssPhp\\Formatter\\Expanded' : 'Leafo\\ScssPhp\\Formatter\\Compressed');
         return $this->fixPaths($objCompiler->compile($content), $arrFile);
     } else {
         $strPath = dirname($arrFile['name']);
         $arrOptions = array('strictMath' => true, 'compress' => !\Config::get('debugMode'), 'import_dirs' => array(TL_ROOT . '/' . $strPath => $strPath));
         $objParser = new \Less_Parser();
         $objParser->SetOptions($arrOptions);
         $objParser->parse($content);
         return $this->fixPaths($objParser->getCss(), $arrFile);
     }
 }
Exemple #12
0
 /**
  * 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;
 }
Exemple #13
0
<?php

use Leafo\ScssPhp\Server;
use Leafo\ScssPhp\Compiler;
require_once 'PHP/vendor/autoload.php';
$scss = new Compiler();
$scss->setImportPaths('sass/');
$scss->setFormatter("scss_formatter_compressed");
?>

<!doctype html>
<html>
<head>
<meta name="designer" content="Designed by: Adam Dragus - adam@hrneurope.com ">
<meta name="developer" content="Developed by: TesseracT - bottyan.tamas@web-developer.hu | Benedek Nagy - trialshock@gmail.com | Balazs Pentek - myrrdhinn@gmail.com">
<meta name="author" content="HRN - Human Resources Network">
<meta name="keywords" content="HR Tech, HRN">
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
<title>HRN | About</title>

<!-- Open Graph data 
<meta property="og:site_name" content="HRN"/>
<meta property="og:title" content="HRN | The Pan European HR Network"/>
<meta property="og:description" content="HRN – Unleash Your People!"/>
<meta property="og:url" content="http://hrn.io/about">
<meta property="og:type" content="website"/>
<meta property="og:image" content="http://hrn.io/img/preview-images/preview-image-1.jpg" />
<meta property="og:image" content="http://hrn.io/img/preview-images/preview-image-3.jpg" />
<meta property="og:image" content="http://hrn.io/img/preview-images/preview-image-2.jpg" />
-->
 /**
  * Convert the input data.
  *
  * @param string $input The raw content without Front-matter.
  *
  * @return string
  */
 public function convert($input)
 {
     $scss = new Compiler();
     $scss->setFormatter('Leafo\\ScssPhp\\Formatter\\Crunched');
     return $scss->compile($input);
 }
Exemple #15
0
  <textarea id='codes' name="codingSpace" placeholder="Your SCSS here" autofocus="true" tabindex="1" ><?php 
if (isset($_POST['codingSpace'])) {
    echo $_POST['codingSpace'];
}
?>
</textarea>
  <button type="submit" name="submit" value="Draw CSS!" tabindex="2"></button>
  <?php 
use Leafo\ScssPhp\Compiler;
if (isset($_POST['codingSpace'])) {
    $cS = $_POST['codingSpace'];
    require "compiler/scssphp/scss.inc.php";
    $compressing = "Leafo\\ScssPhp\\Formatter\\Expanded";
    $scss = new Compiler();
    ini_set('display_errors', '0');
    $scss->setFormatter($compressing);
    try {
        $outputH = $scss->compile($cS);
        echo "<pre id='outputSpace' name='outputSpace'>" . $outputH . "</pre>";
    } catch (Exception $e) {
        echo "<div id='outputSpace' name='outputSpace'>" . $e->getMessage() . "</div>";
    }
}
?>


</form>
<hr />
Made with help from everyone :). Author: Sachin Kanungo | Fork or post issues: <a href="https://github.com/sachya/SCSS-Playground">Github-SCSS Playground</a>
<script type="text/javascript" src="scripts/behave.js"></script>
<script type="text/javascript" src="scripts/keyboard.js"></script>