setImportPaths() public method

Set import paths
public setImportPaths ( string | array $path )
$path string | array
Exemplo n.º 1
0
 public function compile(Filesystem $files, $source, $dest)
 {
     $scss = $files->get($source);
     $this->compiler->setImportPaths(array_merge([$this->getPath($source)], $this->importPaths));
     $css = $this->compiler->compile($scss);
     $files->put($dest, $css);
 }
Exemplo n.º 2
0
 /**
  * @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;
 }
Exemplo n.º 3
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()];
 }
Exemplo n.º 4
0
 /**
  * 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;
 }
Exemplo n.º 5
0
 /**
  * @return string
  */
 public function getFile()
 {
     // get file contents
     $file_contents = Utilities::getFile($this->file['path']);
     // Create scss parser
     $scss = new Compiler();
     // set load path for imported files
     $scss->setImportPaths(dirname($this->file['path']));
     // Parse file using direct file path
     $contents = $scss->compile($file_contents);
     // fix absolute file paths
     $contents = str_replace(array('../'), str_replace(ROOT, "", dirname($this->file['path'])) . '/../', $contents);
     // get parsed files and store in cache
     $this->cache->save($this->file['hash'] . "parsed_files", $scss->getParsedFiles());
     // return css
     return $contents;
 }
Exemplo n.º 6
0
 /**
  * {@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;
 }
Exemplo n.º 7
0
 /**
  * @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);
 }
Exemplo n.º 8
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);
     }
 }
Exemplo n.º 9
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;
 }
Exemplo n.º 10
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" />
-->
Exemplo n.º 11
0
 /**
  * Constructor
  *
  * @param string                       $dir      Root directory to .scss files
  * @param string                       $cacheDir Cache directory
  * @param \Leafo\ScssPhp\Compiler|null $scss     SCSS compiler instance
  */
 public function __construct($dir, $cacheDir = null, $scss = null)
 {
     $this->dir = $dir;
     if (!isset($cacheDir)) {
         $cacheDir = $this->join($dir, 'scss_cache');
     }
     $this->cacheDir = $cacheDir;
     if (!is_dir($this->cacheDir)) {
         mkdir($this->cacheDir, 0755, true);
     }
     if (!isset($scss)) {
         $scss = new Compiler();
         $scss->setImportPaths($this->dir);
     }
     $this->scss = $scss;
     $this->showErrorsAsCSS = false;
 }
<?php

namespace Leafo\ScssPhp;

use Leafo\ScssPhp\Server;
use Leafo\ScssPhp\Compiler;
require "scss.inc.php";
$scss_folder = '../../scss/';
$scss = new Compiler();
$scss->setImportPaths($scss_folder);
$filename = $scss_folder . $_GET['filename'] . '.scss';
//the name argument is optional
$scss->setLineNumbers(true, $filename);
header("Content-type: text/css");
echo $scss->compile(file_get_contents($filename));
Exemplo n.º 13
0
 /**
  * Compile .scss file
  *
  * @param string $filename Input path (.scss)
  *
  * @see Server::compile()
  * @return array meta data result of the compile
  */
 private function compile($filename)
 {
     $start = microtime(true);
     $scss = new Compiler();
     // set import path directory the input filename resides
     // otherwise @import statements will not find the files
     // and will treat the @import line as css import
     $scss->setImportPaths(dirname($filename));
     $css = $scss->compile(file_get_contents($filename), $filename);
     $elapsed = round(microtime(true) - $start, 4);
     $v = Version::VERSION;
     $ts = date('r', $start);
     $css = "/* compiled by scssphp {$v} on {$ts} ({$elapsed}s) */\n\n" . $css;
     $imports = $scss->getParsedFiles();
     $updated = 0;
     foreach ($imports as $mtime) {
         $updated = max($updated, $mtime);
     }
     return array('elapsed' => $elapsed, 'updated' => $updated, 'content' => $css, 'files' => $imports);
 }