Skip to content

Commit

Permalink
Merge branch 'MDL-62968-master' of git://github.com/mickhawkins/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
sarjona committed Jan 18, 2019
2 parents c092f75 + 341070d commit b577f30
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
42 changes: 38 additions & 4 deletions lib/outputlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ private function __construct($config) {
'parents', 'sheets', 'parents_exclude_sheets', 'plugins_exclude_sheets', 'usefallback',
'javascripts', 'javascripts_footer', 'parents_exclude_javascripts',
'layouts', 'enable_dock', 'enablecourseajax', 'requiredblocks',
'rendererfactory', 'csspostprocess', 'editor_sheets', 'rarrow', 'larrow', 'uarrow', 'darrow',
'rendererfactory', 'csspostprocess', 'editor_sheets', 'editor_scss', 'rarrow', 'larrow', 'uarrow', 'darrow',
'hidefromselector', 'doctype', 'yuicssmodules', 'blockrtlmanipulations',
'lessfile', 'extralesscallback', 'lessvariablescallback', 'blockrendermethod',
'scss', 'extrascsscallback', 'prescsscallback', 'csstreepostprocessor', 'addblockposition',
Expand Down Expand Up @@ -973,6 +973,31 @@ public function editor_css_files() {
return $files;
}

/**
* Compiles and returns the content of the SCSS to be used in editor content
*
* @return string Compiled CSS from the editor SCSS
*/
public function editor_scss_to_css() {
$css = '';

if (!empty($this->editor_scss)) {
$compiler = new core_scss();

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

try {
$css .= $compiler->to_css();
} catch (\Exception $e) {
debugging('Error while compiling editor SCSS: ' . $e->getMessage(), DEBUG_DEVELOPER);
}
}
}

return $css;
}

/**
* Get the stylesheet URL of this theme.
*
Expand Down Expand Up @@ -1270,13 +1295,22 @@ public function get_css_content_debug($type, $subtype, $sheet) {
* @return string CSS markup
*/
public function get_css_content_editor() {
// Do not bother to optimise anything here, just very basic stuff.
$cssfiles = $this->editor_css_files();
$css = '';
$cssfiles = $this->editor_css_files();

// If editor has static CSS, include it.
foreach ($cssfiles as $file) {
$css .= file_get_contents($file)."\n";
}
return $this->post_process($css);

// If editor has SCSS, compile and include it.
if (($convertedscss = $this->editor_scss_to_css())) {
$css .= $convertedscss;
}

$output = $this->post_process($css);

return $output;
}

/**
Expand Down
1 change: 1 addition & 0 deletions theme/boost/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
$THEME->name = 'boost';
$THEME->sheets = [];
$THEME->editor_sheets = [];
$THEME->editor_scss = ['editor'];
$THEME->usefallback = true;
$THEME->scss = function($theme) {
return theme_boost_get_main_scss_content($theme);
Expand Down
2 changes: 2 additions & 0 deletions theme/boost/scss/editor.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* Give editor access to all of bootstrap. */
@import "bootstrap/bootstrap";

0 comments on commit b577f30

Please sign in to comment.