Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 475... Línea 475...
475
     */
475
     */
476
    treatStringsInContent(content, stringMap) {
476
    treatStringsInContent(content, stringMap) {
477
        // Placeholders are in the for [[_sX]] or [[_cX]] where X is the string index.
477
        // Placeholders are in the for [[_sX]] or [[_cX]] where X is the string index.
478
        const stringPattern = /(?<placeholder>\[\[_(?<stringType>[cs])(?<stringIndex>\d+)\]\])/g;
478
        const stringPattern = /(?<placeholder>\[\[_(?<stringType>[cs])(?<stringIndex>\d+)\]\])/g;
Línea 479... Línea 479...
479
 
479
 
480
        // A helpre to fetch the string for a given placeholder.
480
        // A helper to fetch the string for a given placeholder.
481
        const getUpdatedString = ({placeholder, stringType, stringIndex}) => {
481
        const getUpdatedString = ({placeholder, stringType, stringIndex}) => {
482
            if (stringMap.has(placeholder)) {
482
            if (stringMap.has(placeholder)) {
483
                return stringMap.get(placeholder);
483
                return stringMap.get(placeholder);
Línea 491... Línea 491...
491
                    return stringMap.get(placeholder);
491
                    return stringMap.get(placeholder);
492
                }
492
                }
493
            }
493
            }
Línea 494... Línea 494...
494
 
494
 
495
            Log.debug(`Could not find string for pattern ${placeholder}`);
495
            Log.debug(`Could not find string for pattern ${placeholder}`);
496
            return '';
496
            return ''; // Fallback if no match is found.
Línea 497... Línea -...
497
        };
-
 
498
 
-
 
499
        // Find all placeholders in the content and replace them with their respective strings.
-
 
500
        let match;
497
        };
501
        while ((match = stringPattern.exec(content)) !== null) {
-
 
502
            let updatedContent = content.slice(0, match.index);
498
 
Línea -... Línea 499...
-
 
499
        let updatedContent = content; // Start with the original content.
-
 
500
        let placeholderFound = true; // Flag to track if we are still finding placeholders.
-
 
501
 
-
 
502
        // Continue looping until no more placeholders are found in the updated content.
-
 
503
        while (placeholderFound) {
-
 
504
            let match;
-
 
505
            let result = [];
-
 
506
            let lastIndex = 0;
-
 
507
            placeholderFound = false; // Assume no placeholders are found.
-
 
508
 
-
 
509
            // Find all placeholders in the content and replace them with their respective strings.
-
 
510
            while ((match = stringPattern.exec(updatedContent)) !== null) {
-
 
511
                placeholderFound = true; // A placeholder was found, so continue looping.
-
 
512
 
-
 
513
                // Add the content before the matched placeholder.
-
 
514
                result.push(updatedContent.slice(lastIndex, match.index));
-
 
515
 
-
 
516
                // Add the updated string for the placeholder.
-
 
517
                result.push(getUpdatedString(match.groups));
-
 
518
 
-
 
519
                // Update lastIndex to move past the current match.
-
 
520
                lastIndex = match.index + match[0].length;
-
 
521
            }
-
 
522
 
-
 
523
            // Add the remaining part of the content after the last match.
503
            updatedContent += getUpdatedString(match.groups);
524
            result.push(updatedContent.slice(lastIndex));
504
            updatedContent += content.slice(match.index + match.groups.placeholder.length);
525
 
Línea 505... Línea 526...
505
 
526
            // Join the parts of the result array into the updated content.
506
            content = updatedContent;
527
            updatedContent = result.join('');
Línea 507... Línea 528...
507
        }
528
        }
508
 
529
 
509
        return content;
530
        return updatedContent; // Return the fully updated content after all loops.
Línea 548... Línea 569...
548
        const [templateSource] = await Promise.all([
569
        const [templateSource] = await Promise.all([
549
            templateSourcePromise,
570
            templateSourcePromise,
550
            Renderer.getLoader().getTemplate(iconTemplate, themeName),
571
            Renderer.getLoader().getTemplate(iconTemplate, themeName),
551
        ]);
572
        ]);
Línea -... Línea 573...
-
 
573
 
-
 
574
        // Clone context object to avoid manipulating the original context object.
552
 
575
        const templateContext = {...context};
Línea 553... Línea 576...
553
        this.addHelpers(context, themeName);
576
        this.addHelpers(templateContext, themeName);
554
 
577
 
555
        // Render the template.
578
        // Render the template.
556
        const renderedContent = await mustache.render(
579
        const renderedContent = await mustache.render(
557
            templateSource,
580
            templateSource,
558
            context,
581
            templateContext,
559
            // Note: The third parameter is a function that will be called to process partials.
582
            // Note: The third parameter is a function that will be called to process partials.
Línea 560... Línea 583...
560
            (partialName) => Renderer.getLoader().partialHelper(partialName, themeName),
583
            (partialName) => Renderer.getLoader().partialHelper(partialName, themeName),