Skip to content

Commit

Permalink
Merge branch 'MDL-67364-master' of git://github.com/mickhawkins/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Feb 25, 2020
2 parents 88fb49b + 2c78a8f commit 8b64627
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lib/outputlib.php
Expand Up @@ -961,12 +961,31 @@ public function editor_css_files() {
*/
public function editor_scss_to_css() {
$css = '';
$dir = $this->dir;
$filenames = [];

// Use editor_scss file(s) provided by this theme if set.
if (!empty($this->editor_scss)) {
$filenames = $this->editor_scss;
} else {
// If no editor_scss set, move up theme hierarchy until one is found (if at all).
// This is so child themes only need to set editor_scss if an override is required.
foreach (array_reverse($this->parent_configs) as $parentconfig) {
if (!empty($parentconfig->editor_scss)) {
$dir = $parentconfig->dir;
$filenames = $parentconfig->editor_scss;

// Config found, stop looking.
break;
}
}
}

if (!empty($filenames)) {
$compiler = new core_scss();

foreach ($this->editor_scss as $filename) {
$compiler->set_file("{$this->dir}/scss/{$filename}.scss");
foreach ($filenames as $filename) {
$compiler->set_file("{$dir}/scss/{$filename}.scss");

try {
$css .= $compiler->to_css();
Expand Down
38 changes: 38 additions & 0 deletions lib/tests/theme_config_test.php
Expand Up @@ -175,4 +175,42 @@ public function test_editor_css_url_has_revision_and_subrevision() {

$this->assertRegExp("/{$themerevision}_{$themesubrevision}/", $url->out(false));
}

/**
* Confirm that editor_scss_to_css is correctly compiling for themes with no parent.
*/
public function test_editor_scss_to_css_root_theme() {
global $CFG;

$this->resetAfterTest();
$theme = theme_config::load('boost');
$editorscss = $CFG->dirroot.'/theme/boost/scss/editor.scss';

$this->assertTrue(file_exists($editorscss));
$compiler = new core_scss();
$compiler->set_file($editorscss);
$cssexpected = $compiler->to_css();
$cssactual = $theme->editor_scss_to_css();

$this->assertEquals($cssexpected, $cssactual);
}

/**
* Confirm that editor_scss_to_css is compiling for a child theme not overriding its parent's editor SCSS.
*/
public function test_editor_scss_to_css_child_theme() {
global $CFG;

$this->resetAfterTest();
$theme = theme_config::load('classic');
$editorscss = $CFG->dirroot.'/theme/boost/scss/editor.scss';

$this->assertTrue(file_exists($editorscss));
$compiler = new core_scss();
$compiler->set_file($editorscss);
$cssexpected = $compiler->to_css();
$cssactual = $theme->editor_scss_to_css();

$this->assertEquals($cssexpected, $cssactual);
}
}

0 comments on commit 8b64627

Please sign in to comment.