Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking/tdr 9/handlebars 4 upgrade #1373

Draft
wants to merge 14 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion views/build/grunt/portableelement.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module.exports = function (grunt) {
searchPattern: '/views/js/picCreator/**/picCreator.json'
}
];
const deprecatedTypes = ['PCI', 'PIC'];

grunt.config.merge({
portableelement: {
Expand Down Expand Up @@ -239,8 +240,14 @@ module.exports = function (grunt) {
return Promise.resolve([]);
}

let deprecationMsg = '';

if (deprecatedTypes.includes(model.type)) {
deprecationMsg = '[DEPRECATED] ';
}

subcompilationPromises.push([
grunt.log.subhead.bind(null, `${model.type} "${model.id}" found in manifest "${file}" ...`)
grunt.log.subhead.bind(null, `${deprecationMsg}${model.type} "${model.id}" found in manifest "${file}" ...`)
]);

model.map.forEach(compilMap => {
Expand Down
4 changes: 2 additions & 2 deletions views/build/moduleWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2022 (original work) Open Assessment Technologies SA ;
* Copyright (c) 2022-2023 (original work) Open Assessment Technologies SA ;
*/
define([], function () {
'use strict';
Expand All @@ -34,7 +34,7 @@ define([], function () {
return function moduleWriter(moduleName, compiled) {
let handlebars = 'handlebars';
if (isPciRuntime(moduleName)) {
handlebars = 'taoQtiItem/portableLib/handlebars';
handlebars = 'taoQtiItem/portableLib/handlebars_4';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: The idea looks very good. However, we need to make sure that taoQtiItem/portableLib/handlebars_4 is loaded in the first place. Without this, the runtime will declare a dependency on an inexistent package...

See oat-sa/extension-tao-itemqti-pci#379 (comment)

}
return `define('tpl!${moduleName}', ['${handlebars}'], function(hb){ return hb.template(${compiled}); });`;
};
Expand Down
2 changes: 1 addition & 1 deletion views/js/loader/qtiLoader.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion views/js/loader/qtiLoader.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion views/js/loader/taoQtiItem.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion views/js/loader/taoQtiItem.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion views/js/loader/taoQtiItemRunner.es5.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion views/js/loader/taoQtiItemRunner.es5.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion views/js/loader/taoQtiItemRunner.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion views/js/loader/taoQtiItemRunner.min.js.map

Large diffs are not rendered by default.

29 changes: 16 additions & 13 deletions views/js/portableLib/OAT/util/tpl.js
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this file is never even called by any of the PCIs I've tested.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I did not find any usage. However, some 3rd-party PCI providers could use it.

Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,47 @@
* Copyright (c) 2015 (original work) Open Assessment Technologies SA ;
*
*/
define(['taoQtiItem/portableLib/jquery_2_1_1', 'taoQtiItem/portableLib/handlebars'], function($, handlebars){

define([
'taoQtiItem/portableLib/jquery_2_1_1',
'taoQtiItem/portableLib/handlebars_4'
], function($, handlebars){

'use strict';

/**
* Find and compile templates found in the $container
*
*
* @param {jQuery} $container
* @returns {object}
*/
function loadTemplates($container){

var templates = {};
var $templates = $($container.find('[type="text/x-template-manifest"]').html());
$templates.each(function(){

var $template = $(this),
id = $template.data('template-id'),
tplSource = $template.html();

if(id && tplSource){
templates[id] = handlebars.compile(tplSource);
}
}
});

return templates;
}

/**
* Create a template manager object from a JQuery container
*
*
* @param {JQuery} $container
* @returns {Object}
*/
return function tpl($container){

var templates = loadTemplates($container);

return {
exists : function exists(templateId){
return (templateId && templates[templateId]);
Expand Down
Loading
Loading