[LON-CAPA-cvs] cvs: loncom /homework edit.pm /xml lonxml.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Mon, 29 Jan 2007 23:51:20 -0000
albertel Mon Jan 29 18:51:20 2007 EDT
Modified files:
/loncom/xml lonxml.pm
/loncom/homework edit.pm
Log:
- modfying how insertlist looks
- some code simplification
Index: loncom/xml/lonxml.pm
diff -u loncom/xml/lonxml.pm:1.436 loncom/xml/lonxml.pm:1.437
--- loncom/xml/lonxml.pm:1.436 Mon Jan 8 13:44:01 2007
+++ loncom/xml/lonxml.pm Mon Jan 29 18:51:04 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# XML Parser Module
#
-# $Id: lonxml.pm,v 1.436 2007/01/08 18:44:01 albertel Exp $
+# $Id: lonxml.pm,v 1.437 2007/01/29 23:51:04 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1706,13 +1706,13 @@
my ($tag,$descrip,$color,$function,$show,$helpfile,$helpdesc) = split(/,/, $line);
if ($tag) {
$insertlist{"$tagnum.tag"} = $tag;
- $insertlist{"$tagnum.description"} = $descrip;
- $insertlist{"$tagnum.color"} = $color;
- $insertlist{"$tagnum.function"} = $function;
+ $insertlist{"$tag.description"} = $descrip;
+ $insertlist{"$tag.color"} = $color;
+ $insertlist{"$tag.function"} = $function;
if (!defined($show)) { $show='yes'; }
- $insertlist{"$tagnum.show"}= $show;
- $insertlist{"$tagnum.helpfile"} = $helpfile;
- $insertlist{"$tagnum.helpdesc"} = $helpdesc;
+ $insertlist{"$tag.show"}= $show;
+ $insertlist{"$tag.helpfile"} = $helpfile;
+ $insertlist{"$tag.helpdesc"} = $helpdesc;
$insertlist{"$tag.num"}=$tagnum;
$tagnum++;
}
@@ -1726,7 +1726,7 @@
for (my $j=0;$j <=$#which;$j++) {
if ( $which[$j] eq 'Y' ) {
if ($insertlist{"$j.show"} ne 'no') {
- push(@{ $insertlist{"$tag.which"} },$j);
+ push(@{ $insertlist{"$tag.which"} },$insertlist{"$j.tag"});
}
}
}
@@ -1735,30 +1735,31 @@
}
sub description {
- my ($token)=@_;
- my $tagnum;
- my $tag=$token->[1];
- foreach my $namespace (reverse @Apache::lonxml::namespace) {
- my $testtag=$namespace.'::'.$tag;
- $tagnum=$insertlist{"$testtag.num"};
- if (defined($tagnum)) { last; }
- }
- if (!defined ($tagnum)) { $tagnum=$Apache::lonxml::insertlist{"$tag.num"}; }
- return $insertlist{$tagnum.'.description'};
+ my ($token)=@_;
+ my $tag = &get_tag($token);
+ return $insertlist{$tag.'.description'};
}
# Returns a list containing the help file, and the description
sub helpinfo {
- my ($token)=@_;
- my $tagnum;
- my $tag=$token->[1];
- foreach my $namespace (reverse @Apache::lonxml::namespace) {
- my $testtag=$namespace.'::'.$tag;
- $tagnum=$insertlist{"$testtag.num"};
- if (defined($tagnum)) { last; }
- }
- if (!defined ($tagnum)) { $tagnum=$Apache::lonxml::insertlist{"$tag.num"}; }
- return ($insertlist{$tagnum.'.helpfile'}, $insertlist{$tagnum.'.helpdesc'});
+ my ($token)=@_;
+ my $tag = &get_tag($token);
+ return ($insertlist{$tag.'.helpfile'}, $insertlist{$tag.'.helpdesc'});
+}
+
+sub get_tag {
+ my ($token)=@_;
+ my $tagnum;
+ my $tag=$token->[1];
+ foreach my $namespace (reverse(@Apache::lonxml::namespace)) {
+ my $testtag = $namespace.'::'.$tag;
+ $tagnum = $insertlist{"$testtag.num"};
+ last if (defined($tagnum));
+ }
+ if (!defined($tagnum)) {
+ $tagnum = $Apache::lonxml::insertlist{"$tag.num"};
+ }
+ return $insertlist{"$tagnum.tag"};
}
1;
Index: loncom/homework/edit.pm
diff -u loncom/homework/edit.pm:1.103 loncom/homework/edit.pm:1.104
--- loncom/homework/edit.pm:1.103 Thu Jul 27 16:47:02 2006
+++ loncom/homework/edit.pm Mon Jan 29 18:51:19 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# edit mode helpers
#
-# $Id: edit.pm,v 1.103 2006/07/27 20:47:02 albertel Exp $
+# $Id: edit.pm,v 1.104 2007/01/29 23:51:19 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -90,17 +90,10 @@
sub start_table {
my ($token)=@_;
- my $tag = $token->[1];
- my $tagnum;
- foreach my $namespace (reverse @Apache::lonxml::namespace) {
- my $testtag=$namespace.'::'.$tag;
- $tagnum=$Apache::lonxml::insertlist{"$testtag.num"};
- &Apache::lonxml::debug(" $testtag ");
- if (defined($tagnum)) { last; }
- }
- if (!defined ($tagnum)) {$tagnum=$Apache::lonxml::insertlist{"$tag.num"};}
- my $color = $Apache::lonxml::insertlist{"$tagnum.color"};
- &Apache::lonxml::debug(" $tagnum -- $color");
+ my $tag = &Apache::lonxml::get_tag($token);
+
+ my $color = $Apache::lonxml::insertlist{"$tag.color"};
+ &Apache::lonxml::debug(" $tag -- $color");
if (!defined($color)) {
$color = $Apache::edit::colorlist[$Apache::edit::colordepth];
}
@@ -177,20 +170,21 @@
sub get_insert_list {
my ($tagname) = @_;
my $result='';
- my @tagnums= ();
+ my @tags= ();
#&Apache::lonxml::debug("keys ".join("\n",sort(keys(%Apache::lonxml::insertlist))));
if ($Apache::lonxml::insertlist{"$tagname.which"}) {
- push (@tagnums, @{ $Apache::lonxml::insertlist{"$tagname.which"} });
+ push (@tags, @{ $Apache::lonxml::insertlist{"$tagname.which"} });
}
foreach my $namespace (@Apache::lonxml::namespace) {
if ($Apache::lonxml::insertlist{"$namespace".'::'."$tagname.which"}) {
- push (@tagnums, @{ $Apache::lonxml::insertlist{"$namespace".'::'."$tagname.which"} });
+ push (@tags, @{ $Apache::lonxml::insertlist{"$namespace".'::'."$tagname.which"} });
}
}
- if (@tagnums) {
+ if (@tags) {
my %options;
- foreach my $tagnum (@tagnums) {
- my $descrip=$Apache::lonxml::insertlist{"$tagnum.description"};
+ foreach my $tag (@tags) {
+ my $descrip=$Apache::lonxml::insertlist{"$tag.description"};
+ my $tagnum =$Apache::lonxml::insertlist{"$tag.num"};
$options{$descrip} ="<option value=\"$tagnum\">".
$descrip."</option>\n";
}
@@ -228,37 +222,26 @@
sub handle_insert {
if ($env{"form.insert_$Apache::lonxml::curdepth"} eq '') { return ''; }
- my $result;
my $tagnum = $env{"form.insert_$Apache::lonxml::curdepth"};
- my $func=$Apache::lonxml::insertlist{"$tagnum.function"};
- if ($func eq 'default') {
- my $newtag=$Apache::lonxml::insertlist{"$tagnum.tag"};
- my $namespace;
- if ($newtag =~ /::/) { ($namespace,$newtag) = split(/::/,$newtag); }
- $result.="\n<$newtag>\n</$newtag>";
- } else {
- if (defined(&$func)) {
- {
- no strict 'refs';
- $result.=&$func();
- }
- } else {
- my $newtag=$Apache::lonxml::insertlist{"$tagnum.tag"};
- &Apache::lonxml::error("Unable to insert tag ".$Apache::lonxml::curdepth." ($tagnum) $newtag, func was not defined.");
- }
- }
- return $result;
+ return &do_insert($tagnum);
}
sub handle_insertafter {
my $tagname=shift;
- if ($env{"form.insert_after_$tagname\_$Apache::lonxml::curdepth"} eq '')
- { return ''; }
- my $result;
+ if ($env{"form.insert_after_$tagname\_$Apache::lonxml::curdepth"} eq '') {
+ return '';
+ }
my $tagnum =$env{"form.insert_after_$tagname\_$Apache::lonxml::curdepth"};
- my $func=$Apache::lonxml::insertlist{"$tagnum.function"};
+ return &do_insert($tagnum);
+}
+
+sub do_insert {
+ my ($tagnum) = @_;
+ my $result;
+
+ my $newtag = $Apache::lonxml::insertlist{"$tagnum.tag"};
+ my $func = $Apache::lonxml::insertlist{"$newtag.function"};
if ($func eq 'default') {
- my $newtag=$Apache::lonxml::insertlist{"$tagnum.tag"};
my $namespace;
if ($newtag =~ /::/) { ($namespace,$newtag) = split(/::/,$newtag); }
$result.="\n<$newtag>\n</$newtag>";
@@ -269,8 +252,7 @@
$result.=&$func();
}
} else {
- my $newtag=$Apache::lonxml::insertlist{"$tagnum.tag"};
- &Apache::lonxml::error("Unable to insert (after) tag $newtag, $func was not defined. ($tagname $tagnum)");
+ &Apache::lonxml::error("Unable to insert tag $newtag, $func was not defined. ($tagnum)");
}
}
return $result;