Skip to content

Commit

Permalink
Item1194: handle macros in format parameters: fix for trunk
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@2854 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
ArthurClemens authored and ArthurClemens committed Mar 3, 2009
1 parent f7ce23f commit ab7d02a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 6 deletions.
20 changes: 18 additions & 2 deletions EditTablePlugin/lib/Foswiki/Plugins/EditTablePlugin/Core.pm
@@ -1,3 +1,13 @@
=pod
REFACTORING JOB:
- put EDITTABLE params inside table->{params}
- pass the table->{params} to handleEditTableTag so we don't rely on the EDITTABLE regex pattern again
- make sure that text before and after the %EDITTABLE{}% tag are preserved
=cut

package Foswiki::Plugins::EditTablePlugin::Core;

use strict;
Expand Down Expand Up @@ -575,7 +585,7 @@ s/^(\s*)\|(.*)/handleTableRow( $1, $2, $tableNr, $isNewRow, $rowNr, $doEdit, $do
$resultText =~ s/$PLACEHOLDER_BUTTONROW_BOTTOM/$buttonRow/go;
}
}

=pod
if ( $doEdit
&& ( $mode & $MODE->{READ} )
&& ( $paramTableNr == $tableNr ) )
Expand All @@ -586,6 +596,7 @@ s/^(\s*)\|(.*)/handleTableRow( $1, $2, $tableNr, $isNewRow, $rowNr, $doEdit, $do
else {
removeTmpTagInTableTagLine($editTableTag);
}
=cut
$resultText = $editTableTag . "\n" . $resultText;

# render variables (only in view mode)
Expand Down Expand Up @@ -1573,16 +1584,21 @@ sub doEnableEdit {

return 1;
}

=pod
NO LONGER NEEDED?
sub insertTmpTagInTableTagLine {
$_[0] =~
s/( "START_EDITTABLEPLUGIN_TMP_TAG")("END_EDITTABLEPLUGIN_TMP_TAG")/$1$_[1]$2/;
}
=cut

=pod
NO LONGER NEEDED?
sub removeTmpTagInTableTagLine {
$_[0] =~
s/ "START_EDITTABLEPLUGIN_TMP_TAG"(.*?)"END_EDITTABLEPLUGIN_TMP_TAG"//go;
}
=cut

=pod
Expand Down
46 changes: 42 additions & 4 deletions EditTablePlugin/lib/Foswiki/Plugins/EditTablePlugin/Data.pm
Expand Up @@ -11,8 +11,9 @@ Helper class parses tables to take out table texts, and stores table cell data.
=cut

my $RENDER_HACK = "\n<nop>\n";
my $PLACEHOLDER_ESCAPE_TAG = 'E_T_P_NOP';

our $PATTERN_EDITTABLEPLUGIN = qr'%EDITTABLE{(.*?)}%'o;
our $PATTERN_EDITTABLEPLUGIN = qr'%EDITTABLE{(.*)}%'o; # NOTE: greedy match to catch macros inside the parameters - but this requires special handling of TABLE tags directly follow the EDITTABLE tags (on the same line) - see _protectVariablesInEditTableTagLine
our $PATTERN_TABLEPLUGIN = qr'%TABLE(?:{(.*?)})?%'o;

=pod
Expand Down Expand Up @@ -70,6 +71,8 @@ sub parseText {
$topicText .= $RENDER_HACK
; # appended stuff is a hack to handle EDITTABLE correctly if at end

$topicText =~ s/%EDITTABLE{(.*)}%/&_protectVariablesInEditTableTagLine($1)/ge;

foreach ( split( /\n/, $topicText ) ) {

my $doCopyLine = 1;
Expand All @@ -86,14 +89,14 @@ sub parseText {
if (/$PATTERN_TABLEPLUGIN/) {

# EDITTABLE and TABLE on one line (order does not matter)
_putTmpTagInTableTagLine($_);
# NO LONGER NEEDED? _putTmpTagInTableTagLine($_);
}
elsif ( $storedTableRow ne '' ) {

# only EDITTABLE
# store the TABLE tag from the previous line together
# with the current EDITTABLE tag
_putTmpTagInTableTagLine($storedTableRow);
# NO LONGER NEEDED? _putTmpTagInTableTagLine($storedTableRow);
$editTableTag .= $storedTableRow . "\n";
$storedTableRow = '';
}
Expand All @@ -107,7 +110,7 @@ sub parseText {

# TABLE on the line after EDITTABLE
# we will include it in the editTableTag
_putTmpTagInTableTagLine($_);
# NO LONGER NEEDED? _putTmpTagInTableTagLine($_);
$doCopyLine = 0;
$editTableTag .= "\n" . $_;
$hasEditTableTag = 1;
Expand Down Expand Up @@ -165,7 +168,9 @@ sub parseText {
}
my $tableRef;
$tableRef->{'text'} = join( "\n", @tableLines );
_unProtectVariables($editTableTag);
$tableRef->{'tag'} = $editTableTag;

push( @{$editTableObjects}, $tableRef );
$tableNum++;

Expand Down Expand Up @@ -213,10 +218,43 @@ sub _trimCellsInRow {
}
}

=pod
NO LONGER NEEDED?
sub _putTmpTagInTableTagLine {
$_[0] =~
s/(%TABLE{.*?)(}%)/$1 "START_EDITTABLEPLUGIN_TMP_TAG""END_EDITTABLEPLUGIN_TMP_TAG"$2/;
}
=cut

=pod
Temporarily escapes variables by placing $PLACEHOLDER_ESCAPE_TAG after each % character.
Also puts %TABLE{}% tags on a new line to better deal with TablePlugin variables: because $PATTERN_EDITTABLEPLUGIN is greedy this tag would otherwise be grabbed together with the EDITTABLE tag
=cut

sub _protectVariablesInEditTableTagLine {
my ( $tagLine ) = @_;

$tagLine =~ s/%/%$PLACEHOLDER_ESCAPE_TAG/go;

# unprotect TABLE and put in on a new line
$tagLine =~ s/%$PLACEHOLDER_ESCAPE_TAG\s*TABLE/\n%TABLE/go;

return "%EDITTABLE{$tagLine}%";
}

=pod
Removes escaped variables.
=cut

sub _unProtectVariables {
# my $text = $_[0]

$_[0] =~ s/$PLACEHOLDER_ESCAPE_TAG//go;
}

=pod
Expand Down

0 comments on commit ab7d02a

Please sign in to comment.