Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / consolidation / robo / src / Task / Assets / Scss.php
1 <?php
2 namespace Robo\Task\Assets;
3
4 use Robo\Result;
5
6 /**
7  * Compiles scss files.
8  *
9  * ```php
10  * <?php
11  * $this->taskScss([
12  *     'scss/default.scss' => 'css/default.css'
13  * ])
14  * ->importDir('assets/styles')
15  * ->run();
16  * ?>
17  * ```
18  *
19  * Use the following scss compiler in your project:
20  *
21  * ```
22  * "leafo/scssphp": "~0.1",
23  * ```
24  *
25  * You can implement additional compilers by extending this task and adding a
26  * method named after them and overloading the scssCompilers() method to
27  * inject the name there.
28  */
29 class Scss extends CssPreprocessor
30 {
31     const FORMAT_NAME = 'scss';
32
33     /**
34      * @var string[]
35      */
36     protected $compilers = [
37         'scssphp', // https://github.com/leafo/scssphp
38     ];
39
40     /**
41      * scssphp compiler
42      * @link https://github.com/leafo/scssphp
43      *
44      * @param string $file
45      *
46      * @return string
47      */
48     protected function scssphp($file)
49     {
50         if (!class_exists('\Leafo\ScssPhp\Compiler')) {
51             return Result::errorMissingPackage($this, 'scssphp', 'leafo/scssphp');
52         }
53
54         $scssCode = file_get_contents($file);
55         $scss = new \Leafo\ScssPhp\Compiler();
56
57         // set options for the scssphp compiler
58         if (isset($this->compilerOptions['importDirs'])) {
59             $scss->setImportPaths($this->compilerOptions['importDirs']);
60         }
61
62         if (isset($this->compilerOptions['formatter'])) {
63             $scss->setFormatter($this->compilerOptions['formatter']);
64         }
65
66         return $scss->compile($scssCode);
67     }
68
69     /**
70      * Sets the formatter for scssphp
71      *
72      * The method setFormatter($formatterName) sets the current formatter to $formatterName,
73      * the name of a class as a string that implements the formatting interface. See the source
74      * for Leafo\ScssPhp\Formatter\Expanded for an example.
75      *
76      * Five formatters are included with leafo/scssphp:
77      * - Leafo\ScssPhp\Formatter\Expanded
78      * - Leafo\ScssPhp\Formatter\Nested (default)
79      * - Leafo\ScssPhp\Formatter\Compressed
80      * - Leafo\ScssPhp\Formatter\Compact
81      * - Leafo\ScssPhp\Formatter\Crunched
82      *
83      * @link http://leafo.github.io/scssphp/docs/#output-formatting
84      *
85      * @param string $formatterName
86      *
87      * @return $this
88      */
89     public function setFormatter($formatterName)
90     {
91         return parent::setFormatter($formatterName);
92     }
93 }