/** * Return the CSS content generated from the SCSS file. * * @param bool $themedesigner True if theme designer is enabled. * @return bool|string Return false when the compilation failed. Else the compiled string. */ protected function get_css_content_from_scss($themedesigner) { global $CFG; $scssfile = $this->scssfile; if (!$scssfile || !is_readable($this->dir . '/scss/' . $scssfile . '.scss')) { throw new coding_exception('The theme did not define a SCSS file, or it is not readable.'); } // We might need more memory to do this, so let's play safe. raise_memory_limit(MEMORY_EXTRA); // Files list. $files = $this->get_css_files($themedesigner); // Get the SCSS file path. $themescssfile = $files['theme'][$scssfile]; // Set-up the compiler. $compiler = new core_scss(); $compiler->set_file($themescssfile); $compiler->append_raw_scss($this->get_extra_scss_code()); $compiler->add_variables($this->get_scss_variables()); try { // Compile! $compiled = $compiler->to_css(); } catch (\Leafo\ScssPhp\Exception $e) { $compiled = false; debugging('Error while compiling SCSS ' . $scssfile . ' file: ' . $e->getMessage(), DEBUG_DEVELOPER); } // Try to save memory. $compiler = null; unset($compiler); return $compiled; }
/** * Return the CSS content generated from the SCSS file. * * @param bool $themedesigner True if theme designer is enabled. * @return bool|string Return false when the compilation failed. Else the compiled string. */ protected function get_css_content_from_scss($themedesigner) { global $CFG; list($paths, $scss) = $this->get_scss_property(); if (!$scss) { throw new coding_exception('The theme did not define a SCSS file, or it is not readable.'); } // We might need more memory to do this, so let's play safe. raise_memory_limit(MEMORY_EXTRA); // Set-up the compiler. $compiler = new core_scss(); $compiler->prepend_raw_scss($this->get_pre_scss_code()); if (is_string($scss)) { $compiler->set_file($scss); } else { $compiler->append_raw_scss($scss($this)); $compiler->setImportPaths($paths); } $compiler->append_raw_scss($this->get_extra_scss_code()); try { // Compile! $compiled = $compiler->to_css(); } catch (\Leafo\ScssPhp\Exception $e) { $compiled = false; debugging('Error while compiling SCSS: ' . $e->getMessage(), DEBUG_DEVELOPER); } // Try to save memory. $compiler = null; unset($compiler); return $compiled; }