Permalink
Browse files

show lists in their entirety if short enough

if a list renders to less than 30 characters, show it. Otherwise, show
    "List of N items"
  • Loading branch information...
christianp committed Aug 16, 2017
1 parent 5209919 commit 2a086c12bb34e1f8b25b03075ec1dac97da0642b
Showing with 20 additions and 3 deletions.
  1. +6 −1 editor/static/js/editor.js
  2. +8 −0 editor/static/js/numbas/numbas-runtime.js
  3. +6 −2 editor/static/js/question/edit.js
@@ -1307,7 +1307,12 @@ $(document).ready(function() {
case 'string':
return Numbas.util.escapeHTML(v.value);
case 'list':
return 'List of '+v.value.length+' '+Numbas.util.pluralise(v.value.length,'item','items');
var s = Numbas.jme.display.treeToJME({tok:v});
if(s.length<30) {
return s;
} else {
return 'List of '+v.value.length+' '+Numbas.util.pluralise(v.value.length,'item','items');
}
case 'html':
if(v.value.length==1 && v.value[0].tagName=='IMG') {
var src = v.value[0].getAttribute('src');
@@ -3656,6 +3656,14 @@ jme.substituteTreeOps.filter = function(tree,scope,allowUnbound) {
return tree;
}

function tok_is_true(item){return item.type=='boolean' && item.value}
newBuiltin('all',[TList],TBool,function(list) {
return list.every(tok_is_true);
});
newBuiltin('some',[TList],TBool,function(list) {
return list.some(tok_is_true);
});

newBuiltin('let',['?'],TList, null, {
evaluate: function(args,scope)
{
@@ -1383,7 +1383,12 @@ $(document).ready(function() {
case 'string':
return Numbas.util.escapeHTML(v.value);
case 'list':
return 'List of '+v.value.length+' '+Numbas.util.pluralise(v.value.length,'item','items');
var s = Numbas.jme.display.treeToJME({tok:v});
if(s.length<30) {
return s;
} else {
return 'List of '+v.value.length+' '+Numbas.util.pluralise(v.value.length,'item','items');
}
case 'html':
if(v.value.length==1 && v.value[0].tagName=='IMG') {
var src = v.value[0].getAttribute('src');
@@ -2116,7 +2121,6 @@ $(document).ready(function() {
var res = part.mark_answer(part.rawStudentAnswerAsJME());
mt.last_run({script: part.markingScript, result: res, marks: part.marks});
}).catch(function(e) {
console.log(e.stack);
mt.last_run({error:e.message});
});
},this).extend({throttle:300});

0 comments on commit 2a086c1

Please sign in to comment.