MDL-59261 theme_boost: compiled css fallback

This commit is contained in:
Bas Brands 2018-06-21 17:56:30 +02:00 committed by Ryan Wyllie
parent f61ee4e857
commit af9edb2e6a
8 changed files with 17932 additions and 39 deletions

View File

@ -2,6 +2,7 @@
theme/bootstrapbase/style/
theme/clean/style/custom.css
theme/more/style/custom.css
theme/boost/style/moodle.css
node_modules/
vendor/
admin/tool/policy/amd/src/jquery-eu-cookie-law-popup.js

View File

@ -137,6 +137,16 @@ module.exports = function(grunt) {
}
}
},
sass: {
dist: {
files: {
"theme/boost/style/moodle.css": "theme/boost/scss/preset/default.scss"
}
},
options: {
includePaths: ["theme/boost/scss/"]
}
},
watch: {
options: {
nospawn: true // We need not to spawn so config can be changed dynamically.
@ -214,7 +224,8 @@ module.exports = function(grunt) {
'# Generated by "grunt ignorefiles"',
'theme/bootstrapbase/style/',
'theme/clean/style/custom.css',
'theme/more/style/custom.css'
'theme/more/style/custom.css',
'theme/boost/style/moodle.css'
].concat(thirdPartyPaths);
grunt.file.write('.stylelintignore', stylelintIgnores.join('\n'));
};
@ -362,6 +373,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-sass');
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-stylelint');
@ -374,7 +386,7 @@ module.exports = function(grunt) {
grunt.registerTask('js', ['amd', 'yui']);
// Register CSS taks.
grunt.registerTask('css', ['stylelint:scss', 'stylelint:less', 'less:bootstrapbase', 'stylelint:css']);
grunt.registerTask('css', ['stylelint:scss', 'sass', 'stylelint:less', 'less:bootstrapbase', 'stylelint:css']);
// Register the startup task.
grunt.registerTask('startup', 'Run the correct tasks for the current directory', tasks.startup);

View File

@ -662,6 +662,12 @@ class theme_config {
*/
public $remapiconcache = [];
/**
* The name of the function to call to get precompiled CSS.
* @var string
*/
public $precompiledcsscallback = null;
/**
* Load the config.php file for a particular theme, and return an instance
* of this class. (That is, this is a factory method.)
@ -739,7 +745,8 @@ class theme_config {
'rendererfactory', 'csspostprocess', 'editor_sheets', 'rarrow', 'larrow', 'uarrow', 'darrow',
'hidefromselector', 'doctype', 'yuicssmodules', 'blockrtlmanipulations',
'lessfile', 'extralesscallback', 'lessvariablescallback', 'blockrendermethod',
'scss', 'extrascsscallback', 'prescsscallback', 'csstreepostprocessor', 'addblockposition', 'iconsystem');
'scss', 'extrascsscallback', 'prescsscallback', 'csstreepostprocessor', 'addblockposition',
'iconsystem', 'precompiledcsscallback');
foreach ($config as $key=>$value) {
if (in_array($key, $configurable)) {
@ -1090,7 +1097,13 @@ class theme_config {
} else {
if ($type === 'theme' && $identifier === self::SCSS_KEY) {
// We need the content from SCSS because this is the SCSS file from the theme.
$csscontent .= $this->get_css_content_from_scss(false);
if ($compiled = $this->get_css_content_from_scss(false)) {
$csscontent .= $compiled;
} else {
// The compiler failed so default back to any precompiled css that might
// exist.
$csscontent .= $this->get_precompiled_css_content();
}
} else if ($type === 'theme' && $identifier === $this->lessfile) {
// We need the content from LESS because this is the LESS file from the theme.
$csscontent .= $this->get_css_content_from_less(false);
@ -1487,6 +1500,26 @@ class theme_config {
return $compiled;
}
/**
* Return the precompiled CSS if the precompiledcsscallback exists.
*
* @return string Return compiled css.
*/
public function get_precompiled_css_content() {
$configs = [$this] + $this->parent_configs;
$css = '';
foreach ($configs as $config) {
if (isset($config->precompiledcsscallback)) {
$function = $config->precompiledcsscallback;
if (function_exists($function)) {
$css .= $function($this);
}
}
}
return $css;
}
/**
* Get the icon system to use.
*

936
npm-shrinkwrap.json generated

File diff suppressed because it is too large Load Diff

View File

@ -12,6 +12,7 @@
"grunt-contrib-uglify": "1.0.1",
"grunt-contrib-watch": "1.0.0",
"grunt-eslint": "20.1.0",
"grunt-sass": "2.1.0",
"grunt-stylelint": "0.6.0",
"semver": "5.3.0",
"shifter": "0.5.0",

View File

@ -150,6 +150,7 @@ $THEME->enable_dock = false;
$THEME->csstreepostprocessor = 'theme_boost_css_tree_post_processor';
$THEME->extrascsscallback = 'theme_boost_get_extra_scss';
$THEME->prescsscallback = 'theme_boost_get_pre_scss';
$THEME->precompiledcsscallback = 'theme_boost_get_precompiled_css';
$THEME->yuicssmodules = array();
$THEME->rendererfactory = 'theme_overridden_renderer_factory';
$THEME->requiredblocks = '';

View File

@ -109,6 +109,16 @@ function theme_boost_get_main_scss_content($theme) {
return $scss;
}
/**
* Get compiled css.
*
* @return string compiled css
*/
function theme_boost_get_precompiled_css() {
global $CFG;
return file_get_contents($CFG->dirroot . '/theme/boost/style/moodle.css');
}
/**
* Get SCSS to prepend.
*

16969
theme/boost/style/moodle.css Normal file

File diff suppressed because it is too large Load Diff