| 
									
										
										
										
											2020-04-18 17:45:11 -06:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2023-01-02 11:17:40 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @package    Grav\Plugin\Admin | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @copyright  Copyright (c) 2015 - 2023 Trilby Media, LLC. All rights reserved. | 
					
						
							|  |  |  |  * @license    MIT License; see LICENSE file for details. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-18 17:45:11 -06:00
										 |  |  | namespace Grav\Plugin\Admin; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use ScssPhp\ScssPhp\Compiler; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ScssCompiler | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     protected $compiler; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function compiler() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if ($this->compiler === null) { | 
					
						
							|  |  |  |             $this->reset(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return $this->compiler; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function reset() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->compiler = new Compiler(); | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-20 13:08:23 -06:00
										 |  |  |     public function setVariables(array $variables) | 
					
						
							| 
									
										
										
										
											2020-04-18 17:45:11 -06:00
										 |  |  |     { | 
					
						
							|  |  |  |         $this->compiler()->setVariables($variables); | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-20 13:08:23 -06:00
										 |  |  |     public function setImportPaths(array $paths) | 
					
						
							| 
									
										
										
										
											2020-04-18 17:45:11 -06:00
										 |  |  |     { | 
					
						
							|  |  |  |         $this->compiler()->setImportPaths($paths); | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-20 13:08:23 -06:00
										 |  |  |     public function compile(string $input_file, string $output_file) | 
					
						
							| 
									
										
										
										
											2020-04-18 17:45:11 -06:00
										 |  |  |     { | 
					
						
							|  |  |  |         $input = file_get_contents($input_file); | 
					
						
							|  |  |  |         $output = $this->compiler()->compile($input); | 
					
						
							|  |  |  |         file_put_contents($output_file, $output); | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-20 13:08:23 -06:00
										 |  |  |     public function compileAll(array $input_paths, string $output_file) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $input = ''; | 
					
						
							|  |  |  |         foreach ($input_paths as $input_file) { | 
					
						
							|  |  |  |             $input .= trim(file_get_contents($input_file)) . "\n\n"; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $output = $this->compiler()->compile($input); | 
					
						
							|  |  |  |         file_put_contents($output_file, $output); | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-18 17:45:11 -06:00
										 |  |  | } |