MDL-56989 boost: don't double-escape page titles
[moodle.git] / lib / classes / scss.php
blob5a5e2abbd21b4bf7e963d8cb4477ef7575393e4a
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Moodle implementation of SCSS.
20 * @package core
21 * @copyright 2016 Frédéric Massart
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') || die();
27 /**
28 * Moodle SCSS compiler class.
30 * @package core
31 * @copyright 2016 Frédéric Massart
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34 class core_scss extends \Leafo\ScssPhp\Compiler {
36 /** @var string The path to the SCSS file. */
37 protected $scssfile;
38 /** @var array Bits of SCSS content to prepend. */
39 protected $scssprepend = array();
40 /** @var array Bits of SCSS content. */
41 protected $scsscontent = array();
43 /**
44 * Add variables.
46 * @param array $scss Associative array of variables and their values.
47 * @return void
49 public function add_variables(array $variables) {
50 $this->setVariables($variables);
53 /**
54 * Append raw SCSS to what's to compile.
56 * @param string $scss SCSS code.
57 * @return void
59 public function append_raw_scss($scss) {
60 $this->scsscontent[] = $scss;
63 /**
64 * Prepend raw SCSS to what's to compile.
66 * @param string $scss SCSS code.
67 * @return void
69 public function prepend_raw_scss($scss) {
70 $this->scssprepend[] = $scss;
73 /**
74 * Set the file to compile from.
76 * The purpose of this method is to provide a way to import the
77 * content of a file without messing with the import directories.
79 * @param string $filepath The path to the file.
80 * @return void
82 public function set_file($filepath) {
83 $this->scssfile = $filepath;
84 $this->setImportPaths([dirname($filepath)]);
87 /**
88 * Compiles to CSS.
90 * @return string
92 public function to_css() {
93 $content = implode(';', $this->scssprepend);
94 if (!empty($this->scssfile)) {
95 $content .= file_get_contents($this->scssfile);
97 $content .= implode(';', $this->scsscontent);
98 return $this->compile($content);