Merge branch 'MDL-70802-39' of git://github.com/andrewnicols/moodle into MOODLE_39_STABLE

This commit is contained in:
Eloy Lafuente (stronk7) 2021-04-08 18:38:58 +02:00
commit 471d1a4b6d
3 changed files with 50 additions and 15 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -68,6 +68,22 @@ define([
/** @var {Array} blacklistedNestedHelpers - List of helpers that can't be called within other helpers */ /** @var {Array} blacklistedNestedHelpers - List of helpers that can't be called within other helpers */
var blacklistedNestedHelpers = ['js']; var blacklistedNestedHelpers = ['js'];
/**
* Normalise the provided component such that '', 'moodle', and 'core' are treated consistently.
*
* @param {String} component
* @returns {String}
*/
var getNormalisedComponent = function(component) {
if (component) {
if (component !== 'moodle' && component !== 'core') {
return component;
}
}
return 'core';
};
/** /**
* Search the various caches for a template promise for the given search key. * Search the various caches for a template promise for the given search key.
* The search key should be in the format <theme>/<component>/<template> e.g. boost/core/modal. * The search key should be in the format <theme>/<component>/<template> e.g. boost/core/modal.
@ -133,7 +149,7 @@ define([
var requests = []; var requests = [];
// Get a list of promises for each of the templates we need to load. // Get a list of promises for each of the templates we need to load.
var templatePromises = templatesToLoad.map(function(templateData) { var templatePromises = templatesToLoad.map(function(templateData) {
var component = templateData.component; var component = getNormalisedComponent(templateData.component);
var name = templateData.name; var name = templateData.name;
var searchKey = templateData.searchKey; var searchKey = templateData.searchKey;
var theme = templateData.theme; var theme = templateData.theme;
@ -177,6 +193,7 @@ define([
// Process all of the template dependencies for this template and add // Process all of the template dependencies for this template and add
// them to the caches so that we don't request them again later. // them to the caches so that we don't request them again later.
response.templates.forEach(function(data) { response.templates.forEach(function(data) {
data.component = getNormalisedComponent(data.component);
// Generate the search key for this template in the response so that we // Generate the search key for this template in the response so that we
// can add it to the caches. // can add it to the caches.
var tempSearchKey = [theme, data.component, data.name].join('/'); var tempSearchKey = [theme, data.component, data.name].join('/');
@ -200,7 +217,7 @@ define([
// with them now so that we don't need to re-fetch them. // with them now so that we don't need to re-fetch them.
str.cache_strings(response.strings.map(function(data) { str.cache_strings(response.strings.map(function(data) {
return { return {
component: data.component, component: getNormalisedComponent(data.component),
key: data.name, key: data.name,
value: data.value value: data.value
}; };
@ -315,7 +332,7 @@ define([
// This is the first time this has been requested so let's add it to the buffer // This is the first time this has been requested so let's add it to the buffer
// to be loaded. // to be loaded.
var parts = templateName.split('/'); var parts = templateName.split('/');
var component = parts.shift(); var component = getNormalisedComponent(parts.shift());
var name = parts.join('/'); var name = parts.join('/');
var deferred = $.Deferred(); var deferred = $.Deferred();
@ -361,7 +378,7 @@ define([
// This is the first time this has been requested so let's add it to the buffer to be loaded. // This is the first time this has been requested so let's add it to the buffer to be loaded.
var parts = templateName.split('/'); var parts = templateName.split('/');
var component = parts.shift(); var component = getNormalisedComponent(parts.shift());
var name = parts.join('/'); var name = parts.join('/');
// Add this template to the buffer to be loaded. // Add this template to the buffer to be loaded.
@ -409,6 +426,7 @@ define([
Renderer.prototype.renderIcon = function(key, component, title) { Renderer.prototype.renderIcon = function(key, component, title) {
// Preload the module to do the icon rendering based on the theme iconsystem. // Preload the module to do the icon rendering based on the theme iconsystem.
var modulename = config.iconsystemmodule; var modulename = config.iconsystemmodule;
component = getNormalisedComponent(component);
// RequireJS does not return a promise. // RequireJS does not return a promise.
var ready = $.Deferred(); var ready = $.Deferred();
@ -425,7 +443,12 @@ define([
return ready.then(function(iconSystem) { return ready.then(function(iconSystem) {
return this.getTemplate(iconSystem.getTemplateName()); return this.getTemplate(iconSystem.getTemplateName());
}.bind(this)).then(function(template) { }.bind(this)).then(function(template) {
return iconSystem.renderIcon(key, component, title, template); return iconSystem.renderIcon(
key,
component,
title,
template
);
}); });
}; };
@ -456,15 +479,21 @@ define([
} }
var templateName = iconSystem.getTemplateName(); var templateName = iconSystem.getTemplateName();
var searchKey = this.currentThemeName + '/' + templateName; var searchKey = this.currentThemeName + '/' + templateName;
var template = templateCache[searchKey]; var template = templateCache[searchKey];
component = getNormalisedComponent(component);
// The key might have been escaped by the JS Mustache engine which // The key might have been escaped by the JS Mustache engine which
// converts forward slashes to HTML entities. Let us undo that here. // converts forward slashes to HTML entities. Let us undo that here.
key = key.replace(/&#x2F;/gi, '/'); key = key.replace(/&#x2F;/gi, '/');
return iconSystem.renderIcon(key, component, text, template); return iconSystem.renderIcon(
key,
component,
text,
template
);
}; };
/** /**
@ -508,9 +537,7 @@ define([
param = parts.join(',').trim(); param = parts.join(',').trim();
} }
if (!component || component === 'moodle') { component = getNormalisedComponent(component);
component = 'core';
}
if (param !== '') { if (param !== '') {
// Allow variable expansion in the param part only. // Allow variable expansion in the param part only.
@ -522,7 +549,11 @@ define([
} }
var index = this.requiredStrings.length; var index = this.requiredStrings.length;
this.requiredStrings.push({key: key, component: component, param: param}); this.requiredStrings.push({
key: key,
component: component,
param: param
});
// The placeholder must not use {{}} as those can be misinterpreted by the engine. // The placeholder must not use {{}} as those can be misinterpreted by the engine.
return '[[_s' + index + ']]'; return '[[_s' + index + ']]';
@ -545,7 +576,7 @@ define([
// This involves wrapping {{, and }} in change delimeter tags. // This involves wrapping {{, and }} in change delimeter tags.
content = content content = content
.replace(/"/g, '\\"') .replace(/"/g, '\\"')
.replace(/([\{\}]{2,3})/g, '{{=<% %>=}}$1<%={{ }}=%>') .replace(/([{}]{2,3})/g, '{{=<% %>=}}$1<%={{ }}=%>')
.replace(/(\r\n|\r|\n)/g, '&#x0a;') .replace(/(\r\n|\r|\n)/g, '&#x0a;')
; ;
return '"' + content + '"'; return '"' + content + '"';
@ -1173,7 +1204,11 @@ define([
*/ */
renderPix: function(key, component, title) { renderPix: function(key, component, title) {
var renderer = new Renderer(); var renderer = new Renderer();
return renderer.renderIcon(key, component, title); return renderer.renderIcon(
key,
getNormalisedComponent(component),
title
);
}, },
/** /**