[LON-CAPA-cvs] cvs: modules /gerd/python convert.pl pythonjs.library
www
www at source.lon-capa.org
Thu Feb 9 20:12:05 EST 2012
www Fri Feb 10 01:12:05 2012 EDT
Added files:
/modules/gerd/python pythonjs.library
Modified files:
/modules/gerd/python convert.pl
Log:
More work on python externalresponse problem converter
Index: modules/gerd/python/convert.pl
diff -u modules/gerd/python/convert.pl:1.2 modules/gerd/python/convert.pl:1.3
--- modules/gerd/python/convert.pl:1.2 Thu Feb 9 02:29:47 2012
+++ modules/gerd/python/convert.pl Fri Feb 10 01:12:05 2012
@@ -14,13 +14,20 @@
foreach my $line (@lines) {
if ($line=~/\{\% block problem \%\}/) {
$mode='outtext';
- $output.="<startouttext />\n";
+ $output.='<import>../lib/pythonjs.library</import>'."\n".
+ '<parameter name="externalurl" type="string" description="URL for external testing" />'.
+ "\n<startouttext />\n";
} elsif ($line=~/\{\% processor \%\}/) {
$mode='script';
$submode='';
$output.="<endouttext />\n<script type='loncapa/perl'>\n";
} elsif ($line=~/\{\% endprocessor \%\}/) {
- $output.="\n".'</script>'."\n";
+ $output.=(<<'ENDSCRIPT');
+$externalurl=¶meter_setting('externalurl');
+unless ($externalurl=~/\w/) { $externalurl='http://localhost.localdomain:8889/pyloncapa.py'; }
+%args=('answer'=>$answer,'preamble'=>$preamble,'test_problem'=>$test_problem);
+</script>
+ENDSCRIPT
$mode='';
} elsif ($mode eq 'outtext') {
$line=~s/<br>/<br \/>\n/gs;
@@ -47,5 +54,8 @@
}
}
}
+$output.='<externalresponse url="$externalurl" form="%args">';
+$output.="\n".'<textfield>'.$initialdisp.'</textfield>'."\n";
+$output.='</externalresponse>'."\n";
$output.="</problem>\n";
print $output;
Index: modules/gerd/python/pythonjs.library
+++ modules/gerd/python/pythonjs.library
<library>
<startouttext />
<script language="javascript">
<!-- Hide from old browsers
function showhide(showHideDiv, switchImgTag) {
var ele = document.getElementById(showHideDiv);
var imageEle = document.getElementById(switchImgTag);
if(ele.style.display == "block") {
ele.style.display = "none";
imageEle.innerHTML = '<img src="/tutorexport/images/plus.png">Show';
}
else {
ele.style.display = "block";
imageEle.innerHTML = '<img src="/tutorexport/images/minus.png">Hide';
}
}
function toggle() {
for (var i = 0; i < arguments.length; i++) {
var e = document.getElementById(arguments[i]);
if (e) {
e.style.display = e.style.display == 'none' ? 'block' : 'none';
}
}
return false;
}
function varToggle(link, id) {
toggle('v' + id);
var s = link.getElementsByTagName('span')[0];
var uarr = String.fromCharCode(0x25b6);
var darr = String.fromCharCode(0x25bc);
s.innerHTML = s.innerHTML == uarr ? darr : uarr;
return false;
}
function highlightText(id,start,end){
textbox = document.getElementById(id);
if (textbox.createTextRange) {
var oRange = this.textbox.createTextRange();
oRange.moveStart("character", start);
oRange.moveEnd("character", length - this.textbox.value.length);
oRange.select();
} else if (this.textbox.setSelectionRange) {
textbox.setSelectionRange(start, end);
}
}
function highlightLine(id,lineno){
lineno = lineno - 1;
textbox = document.getElementById(id);
lines = textbox.value.split('\n');
var start = 0;
var end = 0;
var i=0;
for (i=0; i < lineno; i++){
start += lines[i].length+1;
}
end = start + lines[lineno].length;
highlightText(id,start,end);
}
// -->
</script>
<endouttext />
</library>
More information about the LON-CAPA-cvs
mailing list