--- TWiki-4-04.pm 2006-10-27 13:41:04.160265539 +0200
+++ TWiki.pm 2006-10-27 23:56:32.974488416 +0200
@@ -185,6 +185,7 @@
ICONURLPATH => \&_ICONURLPATH,
IF => \&_IF,
INCLUDE => \&_INCLUDE,
+ INCLUDEPARAMS => \&_INCLUDEPARAMS, # Niels Oct 2006
INTURLENCODE => \&_INTURLENCODE,
LANGUAGES => \&_LANGUAGES,
MAKETEXT => \&_MAKETEXT,
@@ -2645,6 +2646,38 @@
return '';
}
+
+# NielsKolso Oct 2006: Handle default paramters
+sub _INCLUDEPARAMS
+{
+ my ( $this, $defaultParams, $includingTopic, $includingWeb ) = @_;
+
+ return qq(
Error in =%INCLUDEPARAM{...}%!= $defaultParams->{_ERROR}
) if($defaultParams->{_ERROR});
+
+ my $paramtable = "\n\n".
+ "| *%INCLUDE{...}% paramters* |||\n".
+ "| *Name* | *Default value* | *Documentation* |\n";
+
+ foreach (sort keys %$defaultParams)
+ {
+ next if($_ eq '_RAW');
+
+ if($defaultParams->{$_} =~ m/^\s*(.*?)\s*::doc[a-z]*::\s*(.*)$/)
+ {
+ $paramtable.= '| '.join(' | ', "=$_=", (length($1)?''.$1.'':'empty') , "$2")." |\n";
+ }
+ else
+ {
+ $paramtable.= '| '.join(' | ', "=$_=", (length($defaultParams->{$_})?$defaultParams->{$_}:'empty') , "N/A")." |\n";
+ }
+ }
+
+ $paramtable.="
\n";
+
+ return $paramtable;
+}
+
+
# Processes a specific instance %INCLUDE{...}% syntax.
# Returns the text to be inserted in place of the INCLUDE command.
# $topic and $web should be for the immediate parent topic in the
@@ -2721,15 +2754,58 @@
$this->{SESSION_TAGS}{INCLUDINGWEB} = $includingWeb;
$this->{SESSION_TAGS}{INCLUDINGTOPIC} = $includingTopic;
+ ( $meta, $text ) =
+ $this->{store}->readTopic( undef, $includedWeb, $includedTopic,
+ $rev );
+
+ # NielsKoldso Oct 2006
+ # Handle default argument definition - pad actual parameter list
+ if($text =~ m/%INCLUDEPARAMS{(.*?)}%/s)
+ {
+ my %defaultParamsAndDoc;
+ my $defaultParams = new TWiki::Attrs($1);
+ foreach (keys %$defaultParams)
+ {
+ if($defaultParams->{$_} =~ m/^\s*(.*?)\s*::doc[a-z]*::\s*(.*)$/)
+ {
+ $defaultParamsAndDoc{$_}= { value => $1 , documentation => $2 };
+ }
+ else
+ {
+ $defaultParamsAndDoc{$_}= { value => $defaultParams->{$_} , documentation => '' };
+ }
+
+ # Use default attr unless one specified in %INCLDUE{...}%
+ $params->{$_} = $defaultParamsAndDoc{$_}->{'value'} unless(defined $params->{$_});
+ }
+
+ # Now dump parameter table back
+
+ my $paramtable = "\n\n";
+
+ $paramtable.="
\n".
+ "Error in =%INCLUDEPARAM{...}%= $defaultParams->{_ERROR}\n".
+ "
\n" if($defaultParams->{_ERROR});
+
+ $paramtable.= "| *%
INCLUDE{...}% paramters* ||||\n".
+ "| *Name* | *Default value* | *Actual value* | *Documentation* |\n";
+ foreach (sort keys %$params)
+ {
+ next if($_ eq '_RAW');
+ $paramtable.= '| '.join(' | ', "=$_="
+ , (length($defaultParamsAndDoc{$_}->{'value'}) ? ''.$defaultParamsAndDoc{$_}->{'value'}.'' :'empty')
+ , '»'.$params->{$_}.'«'
+ , ($defaultParamsAndDoc{$_}->{'documentation'}? $defaultParamsAndDoc{$_}->{'documentation'} :'N/A')) . " |\n";
+ }
+ $paramtable.=" \n";
+ $text =~ s/\s*%INCLUDEPARAMS{(.*?)}%\s*\n?/$paramtable/s;
+ }
+
# copy params into session tags
foreach my $k ( keys %$params ) {
$this->{SESSION_TAGS}{$k} = $params->{$k};
}
- ( $meta, $text ) =
- $this->{store}->readTopic( undef, $includedWeb, $includedTopic,
- $rev );
-
unless( $this->{security}->checkAccessPermission(
'VIEW', $this->{user}, $text, $includedTopic, $includedWeb )) {
if( isTrue( $warn )) {