Example #1
0
    /**
     * 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;
    }