MDL-56959 theme: SCSS file is inherited from parent

Also added support for the SCSS property to be a Closure
and return content rather than simply being the name of a file.
This commit is contained in:
Frederic Massart
2016-11-17 15:18:29 +08:00
parent b4d6669dd0
commit 41b973bcbb
4 changed files with 117 additions and 53 deletions
+3 -1
View File
@@ -27,9 +27,11 @@ defined('MOODLE_INTERNAL') || die();
require_once(__DIR__ . '/lib.php');
$THEME->name = 'boost';
$THEME->scssfile = 'preset';
$THEME->sheets = [];
$THEME->editor_sheets = [];
$THEME->scss = function($theme) {
return theme_boost_get_main_scss_content($theme);
};
$THEME->layouts = [
// Most backwards compatible layout without the blocks - this is the layout used by default.
+38 -26
View File
@@ -46,38 +46,16 @@ function theme_boost_get_extra_scss($theme) {
}
/**
* Get SCSS to prepend.
* Returns the main SCSS content.
*
* @param theme_config $theme The theme config object.
* @return array
* @return string
*/
function theme_boost_get_pre_scss($theme) {
function theme_boost_get_main_scss_content($theme) {
global $CFG;
$scss = '';
$configurable = [
// Config key => [variableName, ...].
'brandcolor' => ['brand-primary'],
];
// Prepend variables first.
foreach ($configurable as $configkey => $targets) {
$value = $theme->settings->{$configkey};
if (empty($value)) {
continue;
}
array_map(function($target) use (&$scss, $value) {
$scss .= '$' . $target . ': ' . $value . ";\n";
}, (array) $targets);
}
// Prepend pre-scss.
if (!empty($theme->settings->scsspre)) {
$scss .= $theme->settings->scsspre;
}
// Now append the preset.
$filename = $theme->settings->preset;
$filename = !empty($theme->settings->preset) ? $theme->settings->preset : null;
$fs = get_file_storage();
$context = context_system::instance();
@@ -94,3 +72,37 @@ function theme_boost_get_pre_scss($theme) {
return $scss;
}
/**
* Get SCSS to prepend.
*
* @param theme_config $theme The theme config object.
* @return array
*/
function theme_boost_get_pre_scss($theme) {
global $CFG;
$scss = '';
$configurable = [
// Config key => [variableName, ...].
'brandcolor' => ['brand-primary'],
];
// Prepend variables first.
foreach ($configurable as $configkey => $targets) {
$value = isset($theme->settings->{$configkey}) ? $theme->settings->{$configkey} : null;
if (empty($value)) {
continue;
}
array_map(function($target) use (&$scss, $value) {
$scss .= '$' . $target . ': ' . $value . ";\n";
}, (array) $targets);
}
// Prepend pre-scss.
if (!empty($theme->settings->scsspre)) {
$scss .= $theme->settings->scsspre;
}
return $scss;
}
+3 -2
View File
@@ -19,9 +19,10 @@ Removed themes:
* CLI svgtool.php has moved from theme/base/cli to admin/cli and paths should be relative to the new location.
* Bootstrap 4 was added as part of a the new theme 'boost'.
* Themes can now automatically compile SCSS on the fly. This works the same way as it
does compiling LESS on the fly, effecitvely adding $THEME->scssfile to your config.
does compiling LESS on the fly, effecitvely adding $THEME->scss to your config.
* Two new callbacks allow themes to inject SCSS code before and after the content provided
by the SCSS file $THEME->scssfile. See $THEME->prescsscallback and $THEME->extrascsscallback.
by the SCSS file $THEME->scss. See $THEME->prescsscallback and $THEME->extrascsscallback.
* $THEME->scss can also be a Closure which will return the main SCSS content.
* Using .dir-rtl for RTL styling is deprecated and should not be used any more. From now
the styles are automatically flipped when the language is right-to-left. However,
as this is not always perfect, you can define exceptions. Please refer to the documentation