[LON-CAPA-cvs] cvs: loncom /homework structuretags.pm

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 03 Apr 2003 14:53:44 -0000


albertel		Thu Apr  3 09:53:44 2003 EDT

  Modified files:              
    /loncom/homework	structuretags.pm 
  Log:
  - editing <block> and <while> actually works now
  
  
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.159 loncom/homework/structuretags.pm:1.160
--- loncom/homework/structuretags.pm:1.159	Thu Apr  3 09:31:58 2003
+++ loncom/homework/structuretags.pm	Thu Apr  3 09:53:44 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: structuretags.pm,v 1.159 2003/04/03 14:31:58 albertel Exp $
+# $Id: structuretags.pm,v 1.160 2003/04/03 14:53:44 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -540,7 +540,7 @@
 
     my $result;
 
-    if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || 
+    if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
 	$target eq 'tex' || $target eq 'analyze') {
 	my $code = $token->[2]->{'condition'};
 	if ($code) {
@@ -572,45 +572,70 @@
 
 sub end_block {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
-    my @result=('','');
-    if ($target eq "edit" || $target eq 'modified') { @result=('','no'); }
-    return (@result);
+    my $result;
+    if ($target eq "edit") {
+	$result.= &Apache::edit::tag_end($target,$token,'');
+    }
+    return $result;
 }
 
 sub start_while {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
 
-    my $code = $token->[2]->{'condition'};
+    &Apache::lonxml::debug('starting while');
+    my $result;
+    if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || 
+	$target eq 'tex' || $target eq 'analyze') {
+	my $code = $token->[2]->{'condition'};
 
-    push( @Apache::structuretags::whileconds, $code); 
-    if (!$Apache::lonxml::default_homework_loaded) {
-	&Apache::lonxml::default_homework_load($safeeval);
-    }
-    my $result = &Apache::run::run($code,$safeeval);
-    my $bodytext=$$parser[$#$parser]->get_text("/while");
-    push( @Apache::structuretags::whilebody, $bodytext);
-    if ( $result ) {
-	&Apache::lonxml::newparser($parser,\$bodytext);
+	push( @Apache::structuretags::whileconds, $code);
+	if (!$Apache::lonxml::default_homework_loaded) {
+	    &Apache::lonxml::default_homework_load($safeeval);
+	}
+	my $result = &Apache::run::run($code,$safeeval);
+	my $bodytext=$$parser[-1]->get_text("/while");
+	push( @Apache::structuretags::whilebody, $bodytext);
+	if ( $result ) {
+	    &Apache::lonxml::newparser($parser,\$bodytext);
+	}
+    } elsif ($target eq 'edit') {
+	$result .=&Apache::edit::tag_start($target,$token);
+	$result .=&Apache::edit::text_arg('Test Condition:','condition',
+					  $token,40);
+	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
+    } elsif ($target eq 'modified') {
+	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
+						     $safeeval,'condition');
+	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
     }
-    return "";
+    return $result;
 }
 
 sub end_while {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
-    my $code = pop @Apache::structuretags::whileconds;
-    my $bodytext = pop @Apache::structuretags::whilebody;
-    my $result = &Apache::run::run($code,$safeeval);
-    if ( $result ) {
-	&Apache::lonxml::newparser($parser,\$bodytext);
+    &Apache::lonxml::debug('ending while');
+
+    my $result;
+
+    if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
+	$target eq 'tex' || $target eq 'analyze') {
+	my $code = pop(@Apache::structuretags::whileconds);
+	my $bodytext = pop(@Apache::structuretags::whilebody);
+	my $result = &Apache::run::run($code,$safeeval);
+	if ( $result ) {
+	    &Apache::lonxml::newparser($parser,\$bodytext);
+	}
+    } elsif ($target eq "edit") {
+	$result.= &Apache::edit::tag_end($target,$token,'');
     }
-    return "";
+    return $result;
 }
 
-# <randomlist show="1"> 
+# <randomlist show="1">
 #  <tag1>..</tag1>
 #  <tag2>..</tag2>
 #  <tag3>..</tag3>
-#  ... 
+#  ...
 # </randomlist>
 sub start_randomlist {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;