--- loncom/xml/scripttag.pm 2001/03/27 16:56:56 1.35
+++ loncom/xml/scripttag.pm 2001/05/04 21:17:24 1.37
@@ -24,12 +24,13 @@ sub start_script {
my $bodytext=&Apache::lonxml::get_all_text("/script",$$parser[$#$parser]);
if ( $target eq "modified" ) {
+ $result=$token->[4].$bodytext;
} elsif ( $target eq "web" || $target eq "grade" ) {
&Apache::run::run($bodytext,$safeeval);
} elsif ($target eq "edit" ) {
&Apache::run::run($bodytext,$safeeval);
$result="
<$token->[1]> output:
$bodytext
Source:
";
- $result.=&editfield($token->[1],$bodytext);
+ $result.=&Apache::edit::editfield($token->[1],$bodytext);
}
} else {
if ($target ne "meta") { $result = $token->[4]; }
@@ -67,7 +68,7 @@ sub start_display {
if ($target eq "edit" ) {
$result =
"
<$token->[1]> output:
$bodytext
Source:
";
- $result.=&editfield($token->[1],$bodytext);
+ $result.=&Apache::edit::editfield($token->[1],$bodytext);
}
return $result;
}
@@ -76,54 +77,96 @@ sub end_display {
}
sub start_scriptlib {
- my ($target,$token,$parstack,$parser,$safeeval)=@_;
- my $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
- my $result ="";
-
- $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
- $$parstack[$#$parstack]);
- my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
- $bodytext);
- my $script=&Apache::lonnet::getfile($location);
- if ($script == -1) {
- &Apache::lonxml::error(" Unable to find $location for scriptlib");
- return "";
+ my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
+ my $bodytext;
+ my $result ='';
+ my $error='';
+
+ if ($target eq 'web' || $target eq 'grade' || $target eq 'meta' || $target eq 'edit') {
+ $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
+ $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
+ $$parstack[$#$parstack]);
+ my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
+ $bodytext);
+ my $script=&Apache::lonnet::getfile($location);
+ if ($script == -1) {
+ if ($target eq 'edit') {
+ $error='
Errors | Unable to find '.$location.' | '."\n";
+ } else {
+ &Apache::lonxml::error(" Unable to find $location for scriptlib");
+ return "";
+ }
+ }
+ &Apache::run::run($script,$safeeval);
+ #&Apache::lonxml::debug("ran $bodytext:
".&Apache::lonnet::getfile($bodytext)."
");
}
- &Apache::run::run($script,$safeeval);
- #&Apache::lonxml::debug("ran $bodytext:
".&Apache::lonnet::getfile($bodytext)."
");
-
if ($target eq "edit" ) {
- $result.=&editfield($token->[1],$bodytext);
+ $result=
+ &Apache::edit::tag_start($token->[1]).
+ &Apache::edit::editfield($token->[1],$bodytext,'New Script Functions').
+ $error;
+ }
+ if ($target eq "modified" ) {
+ $bodytext=$$parser[$#$parser]->get_text("/scriptlib");
+ $result=&Apache::edit::modifiedfield($token);
+ &Apache::lonxml::debug($result);
}
return $result;
}
-sub end_scriptlib {}
+sub end_scriptlib {
+ my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
+ my $result='';
+# if ($target eq "edit" ) { $result=" "; }
+ return $result;
+}
sub start_parserlib {
my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
- my $bodytext=$$parser[$#$parser]->get_text("/parserlib");
+ my $bodytext;
my $result ="";
+ my $error='';
- $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
- $$parstack[$#$parstack]);
- my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
- $bodytext);
- my $styletext=&Apache::lonnet::getfile($location);
- #&Apache::lonxml::debug("found :$bodytext: in :$location: with :$styletext:");
- if ($styletext == -1) {
- &Apache::lonxml::error(" Unable to find $location for parserlib");
- return "";
+ if ($target eq 'web' || $target eq 'grade' || $target eq 'meta' || $target eq 'edit') {
+ $bodytext=$$parser[$#$parser]->get_text("/parserlib");
+ $bodytext=&Apache::run::evaluate($bodytext,$safeeval,
+ $$parstack[$#$parstack]);
+ my $location=&Apache::lonnet::filelocation($Apache::lonxml::pwd['-1'],
+ $bodytext);
+ my $styletext=&Apache::lonnet::getfile($location);
+ #&Apache::lonxml::debug("found :$bodytext: in :$location: with :$styletext:");
+ if ($styletext == -1) {
+ if ($target eq 'edit') {
+ $error='
Errors | Unable to find '.$location.' | '."\n";
+ } else {
+ &Apache::lonxml::error(" Unable to find $location for parserlib");
+ return "";
+ }
+ }
+ %$style = ( %$style , &Apache::style::styleparser($target,$styletext));
}
- %$style = ( %$style , &Apache::style::styleparser($target,$styletext));
-
if ($target eq "edit" ) {
- $result=&editfield($token->[1],$bodytext);
+ $result=
+ &Apache::edit::tag_start($token->[1]).
+ &Apache::edit::editfield($token->[1],$bodytext,"New Tag Definitions").
+ $error;
+ }
+ if ($target eq "modified" ) {
+ $bodytext=$$parser[$#$parser]->get_text("/parserlib");
+ $result=&Apache::edit::modifiedfield($token);
+ &Apache::lonxml::debug($result);
}
return $result;
}
sub end_parserlib {
+ my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
+ my $result='';
+# if ($target eq "edit" ) {
+# $result=&Apache::edit::tag_end($target,$token,$parstack,$parser,
+# $safeeval,$style);
+# }
+ return $result;
}
sub start_window {
@@ -171,7 +214,7 @@ sub start_import {
&Apache::lonxml::newparser($parser,\$file,$dir);
if ($target eq "edit" ) {
- $result.=&editfield($token->[1],$bodytext);
+ $result.=&Apache::edit::editfield($token->[1],$bodytext);
$result.="Clickhere to edit
"
}
return '';
@@ -195,18 +238,6 @@ sub start_meta {
sub end_meta {
}
-sub editfield {
- my ($tag,$data)=@_;
-
- my $count=0;
- my $maxlength=-1;
- map { $count++;
- if (length($_) > $maxlength) { $maxlength = length ($_); }
- } split ("\n", $data);
-
- return "
\n<$tag>
\n
\n</$tag>
\n";
-}
-
sub getfilenothere {
my ($filename) = @_;
my $a="";